云存储 负责管理 Telegram 迷你应用程序中云存储的💠组件。 检查支持要检查当前 Telegram 迷你应用程序版本是否支持云存储,需要使用 isSupported 方法: Variable : - import { cloudStorage } from '@telegram-apps/sdk';
" f [2 @1 e7 `$ H: [+ H8 m6 S5 u( ^
: `& s/ R7 x; O- cloudStorage.isSupported(); // boolean
复制代码 + p% ]- b; H0 }* }: _
Functions : - import { isCloudStorageSupported } from '@telegram-apps/sdk';
% c' [$ u( d9 F
5 x/ _4 I: X+ u: H7 h- isCloudStorageSupported(); // boolean
复制代码 设置项目要设置键值,请使用 setItem 方法。 Variable : - await cloudStorage.setItem('a', 'a-value');
复制代码Functions : - import { setCloudStorageItem } from '@telegram-apps/sdk';
0 N8 d5 Y/ y8 O, x3 M7 ?
6 i' t. ]8 w2 l) b& b6 Q& C, c- await setCloudStorageItem('a', 'a-value');
复制代码 获取钥匙要获取所有现有密钥的列表,请使用 getKeys 方法。 Variable : - const keys = await cloudStorage.getKeys(); // ['a', 'b', 'c']
复制代码Functions : - import { getCloudStorageKeys } from '@telegram-apps/sdk';
6 M3 U. L1 R0 Z* j3 |: R - " e7 l3 X6 j$ T/ `3 B9 U- h
- const keys = await getCloudStorageKeys(); // ['a', 'b', 'c']
复制代码
! E3 T0 d2 L& e8 m2 h要获取特定键或多个键的值,请使用 getItem 方法。 Variable : - const nonExistent = await cloudStorage.getItem('non-existent');
7 L' k& A7 w; a - // The result is an empty string: ''3 H; F" v2 b; H0 q" h
- 1 p8 J2 ~6 y" d( _; x
- const existent = await cloudStorage.getItem('a');
0 e5 J# _* R) G0 ^4 K - // The result is the value of the 'a' key. Example: 'a-value'
/ ^! H- i# S+ |- I
- [8 f+ k( c4 ]- K5 {; @- const values = await cloudStorage.getItem(['a', 'b', 'non-existent']);, y. a' Q4 J) g, c+ P
- // The result is a record of the keys 'a', 'b', and 'non-existent'.
8 I* |$ d5 L% A - // Example:' s2 o4 Y1 \2 Q: s* y* u! b
- // { ( i) H; c9 Y* s$ L: ] i2 E
- // a: 'a-value', / ?" c# n; \" Q: \
- // b: 'b-value',
2 A ]9 I) ?# I& V - // 'non-existent': '', $ u; K, F: y0 M! G4 g9 {
- // }
复制代码Functions : - import { getCloudStorageItem } from '@telegram-apps/sdk';9 Z4 x, x' \0 L" N( J" ^
2 J' c1 K# i' Y. l- o- const nonExistent = await getCloudStorageItem('non-existent');
0 Z: R( a7 P5 P/ ^9 Q0 _. [$ ` - // The result is an empty string: ''" b @* C0 t( q9 R/ Q- H$ W
& D" ^; o W8 B- const existent = await getCloudStorageItem('a');
) ^9 E1 @7 h8 R3 F5 @3 Y - // The result is the value of the 'a' key. Example: 'a-value'- u) M! F5 c; z F) g. @
3 N. h) H; S: G" ~. c8 X1 D- const values = await getCloudStorageItem(['a', 'b', 'non-existent']);/ L* N5 H, O! ]
- // The result is a record of the keys 'a', 'b', and 'non-existent'.
) }2 S6 @! t* C5 q; @0 t; g# P6 V - // Example:
$ v0 D9 b; ~3 I2 ?2 p/ q. M' a% K - // {
- W. a, L0 P; D, N9 F2 P - // a: 'a-value',
( K8 e$ M# C7 \+ ` - // b: 'b-value',
4 R; d+ Y9 V' V, O9 w9 h - // 'non-existent': '',
4 @! H* r' g. o# d4 p2 H/ t* S - // }
复制代码 删除项目要删除一个键或键列表,请使用 deleteItem 方法。 Variable : - await cloudStorage.deleteItem('a');
5 ]9 V& Q% s. x3 u - await cloudStorage.deleteItem(['a', 'b', 'c']);
复制代码Functions : - import { deleteCloudStorageItem } from '@telegram-apps/sdk';+ x2 h* P' o" b! l
% R4 X$ G# k8 \ i. H- await deleteCloudStorageItem('a');- ]5 h. T* f5 x. h9 e1 `
- await deleteCloudStorageItem(['a', 'b', 'c']);
复制代码
! ]5 }: c, t% l) o% b0 c* P, n, W3 ~ I% H
|