@@ -30,7 +30,7 @@ enum HTTPMethod {
30
30
}
31
31
32
32
interface SetOptions {
33
- ttl ?: Date | number
33
+ expiration ?: Date | number
34
34
}
35
35
36
36
interface SetFilesItem extends SetOptions {
@@ -100,7 +100,7 @@ export class Blobs {
100
100
}
101
101
}
102
102
103
- private static getTTLHeaders ( ttl : Date | number | undefined ) : Record < string , string > {
103
+ private static getExpirationeaders ( ttl : Date | number | undefined ) : Record < string , string > {
104
104
if ( typeof ttl === 'number' ) {
105
105
return {
106
106
[ EXPIRY_HEADER ] : ( Date . now ( ) + ttl ) . toString ( ) ,
@@ -186,12 +186,12 @@ export class Blobs {
186
186
) : Promise < ArrayBuffer | Blob | ReadableStream | string | null > {
187
187
const { type } = options ?? { }
188
188
const res = await this . makeStoreRequest ( key , HTTPMethod . Get )
189
- const expiry = res ?. headers . get ( EXPIRY_HEADER )
189
+ const expiration = res ?. headers . get ( EXPIRY_HEADER )
190
190
191
- if ( typeof expiry === 'string' ) {
192
- const expiryTS = Number . parseInt ( expiry )
191
+ if ( typeof expiration === 'string' ) {
192
+ const expirationTS = Number . parseInt ( expiration )
193
193
194
- if ( ! Number . isNaN ( expiryTS ) && expiryTS <= Date . now ( ) ) {
194
+ if ( ! Number . isNaN ( expirationTS ) && expirationTS <= Date . now ( ) ) {
195
195
return null
196
196
}
197
197
}
@@ -223,17 +223,17 @@ export class Blobs {
223
223
throw new Error ( `Invalid 'type' property: ${ type } . Expected: arrayBuffer, blob, json, stream, or text.` )
224
224
}
225
225
226
- async set ( key : string , data : BlobInput , { ttl } : SetOptions = { } ) {
227
- const headers = Blobs . getTTLHeaders ( ttl )
226
+ async set ( key : string , data : BlobInput , { expiration } : SetOptions = { } ) {
227
+ const headers = Blobs . getExpirationeaders ( expiration )
228
228
229
229
await this . makeStoreRequest ( key , HTTPMethod . Put , headers , data )
230
230
}
231
231
232
- async setFile ( key : string , path : string , { ttl } : SetOptions = { } ) {
232
+ async setFile ( key : string , path : string , { expiration } : SetOptions = { } ) {
233
233
const { size } = await stat ( path )
234
234
const file = Readable . toWeb ( createReadStream ( path ) )
235
235
const headers = {
236
- ...Blobs . getTTLHeaders ( ttl ) ,
236
+ ...Blobs . getExpirationeaders ( expiration ) ,
237
237
'content-length' : size . toString ( ) ,
238
238
}
239
239
@@ -244,10 +244,10 @@ export class Blobs {
244
244
return pMap ( files , ( { key, path, ...options } ) => this . setFile ( key , path , options ) , { concurrency } )
245
245
}
246
246
247
- async setJSON ( key : string , data : unknown , { ttl } : SetOptions = { } ) {
247
+ async setJSON ( key : string , data : unknown , { expiration } : SetOptions = { } ) {
248
248
const payload = JSON . stringify ( data )
249
249
const headers = {
250
- ...Blobs . getTTLHeaders ( ttl ) ,
250
+ ...Blobs . getExpirationeaders ( expiration ) ,
251
251
'content-type' : 'application/json' ,
252
252
}
253
253
0 commit comments