English 简体中文 繁體中文 한국 사람 日本語 Deutsch русский بالعربية TÜRKÇE português คนไทย french

简体中文 繁體中文 English 日本語 Deutsch 한국 사람 بالعربية TÜRKÇE คนไทย Français русский

回答

收藏

Telegram 小程序 | TypeScript @telegram-apps/sdk @2.x | 组件 | 云存储

开源社区 开源社区 8599 人阅读 | 0 人回复 | 2025-02-24

云存储

负责管理 Telegram 迷你应用程序中云存储的💠组件

检查支持

要检查当前 Telegram 迷你应用程序版本是否支持云存储,需要使用 isSupported 方法:

Variable :

  1. import { cloudStorage } from '@telegram-apps/sdk';
    " I' b' O$ K6 {" U! j) k, n

  2. # a$ w6 N% f* \) A  V0 g+ F8 d
  3. cloudStorage.isSupported(); // boolean
复制代码
6 `5 ?9 ^6 B9 R3 \' p3 j; G( @# j

Functions :

  1. import { isCloudStorageSupported } from '@telegram-apps/sdk';- i" ~; j/ q6 x

  2. : t, M7 t8 q3 M
  3. isCloudStorageSupported(); // boolean
复制代码
设置项目

要设置键值,请使用 setItem 方法。

Variable :

  1. await cloudStorage.setItem('a', 'a-value');
复制代码

Functions :

  1. import { setCloudStorageItem } from '@telegram-apps/sdk';
    * }" Y' S7 A3 p

  2. , i. {0 ?) d5 s8 j1 k
  3. await setCloudStorageItem('a', 'a-value');
复制代码
获取钥匙

要获取所有现有密钥的列表,请使用 getKeys 方法。

Variable :

  1. const keys = await cloudStorage.getKeys(); // ['a', 'b', 'c']
复制代码

Functions :

  1. import { getCloudStorageKeys } from '@telegram-apps/sdk';  D  |0 U9 x5 Y
  2. : m- Q) P6 F/ o, g8 J  @
  3. const keys = await getCloudStorageKeys(); // ['a', 'b', 'c']
复制代码

+ B5 U; f& w+ R+ B  B

要获取特定键或多个键的值,请使用 getItem 方法。

Variable :

  1. const nonExistent = await cloudStorage.getItem('non-existent');
    ' F2 P2 E+ T2 b/ w3 a7 G
  2. // The result is an empty string: ''
    ' A) X0 G# X8 q: b

  3. * i7 t1 M4 |( t3 t$ i: r6 C) D
  4. const existent = await cloudStorage.getItem('a');
    + q5 T8 c+ ?1 y! D  x/ p: }5 |$ i: `, X
  5. // The result is the value of the 'a' key. Example: 'a-value'
    * v) P  b/ n9 S7 _5 s
  6. / L0 T/ ~$ B3 e0 I6 \7 C* ^
  7. const values = await cloudStorage.getItem(['a', 'b', 'non-existent']);
    7 W' f, {8 |. u& Z& K9 g  t2 H/ Q( _
  8. // The result is a record of the keys 'a', 'b', and 'non-existent'.
    $ A0 d4 K) t3 Q$ N% r: G
  9. // Example:
    3 J) N: c" t/ V0 ?- d
  10. // {
    / R5 q# v) v5 F
  11. //   a: 'a-value', * K7 k. B; Z  `  j4 k: `8 I
  12. //   b: 'b-value', , [' }- [: A! I
  13. //   'non-existent': '',
      `! J9 U2 z4 J4 ]% p* f/ S
  14. // }
复制代码

Functions :

  1. import { getCloudStorageItem } from '@telegram-apps/sdk';  N) P7 Q* r# Q- [0 r& \% V

  2. 9 h/ c  B. O: M5 A- R8 I
  3. const nonExistent = await getCloudStorageItem('non-existent');
    ) y( |1 ], d' m4 ~& b$ i
  4. // The result is an empty string: ''
    * R' q6 p" w  P$ o+ g; w

  5. / @6 W' U- ]6 l( v
  6. const existent = await getCloudStorageItem('a');
    1 }3 h/ E: n) S" C
  7. // The result is the value of the 'a' key. Example: 'a-value'+ D! f/ h+ ]# i
  8. 5 `6 P, _, M% H# E  P
  9. const values = await getCloudStorageItem(['a', 'b', 'non-existent']);8 b4 d1 ^  N6 D) @3 N; P; K
  10. // The result is a record of the keys 'a', 'b', and 'non-existent'. 8 `4 {1 n7 ^8 R
  11. // Example:
    + Z1 z  g+ Y6 B
  12. // { 4 h9 E$ x2 x1 {7 X
  13. //   a: 'a-value',
    ( F% R5 N- H$ [
  14. //   b: 'b-value',
    8 J/ u# e+ R9 w" ~3 Z7 w% z0 K7 M
  15. //   'non-existent': '', 3 [' C1 s7 K0 b. k- M
  16. // }
复制代码
删除项目

要删除一个键或键列表,请使用 deleteItem 方法。

Variable :

  1. await cloudStorage.deleteItem('a');8 w; p5 J7 S* M% T) v
  2. await cloudStorage.deleteItem(['a', 'b', 'c']);
复制代码

Functions :

  1. import { deleteCloudStorageItem } from '@telegram-apps/sdk';  E5 s- z; @& `$ R" I: b

  2. $ A. }" @/ F! t
  3. await deleteCloudStorageItem('a');8 ~: e3 u& P6 M- k( o9 ~
  4. await deleteCloudStorageItem(['a', 'b', 'c']);
复制代码

6 C& [0 @$ n  {  l# _) R8 y" H- E/ F. e" J2 J0 t# Y
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则