An ATproto social media client -- with an independent Appview.

Delete the entire temporary directory instead of just the temp file, also use `cacheDirectory` over `documentDirectory` (#3985)

* lint

* remove extra arg

authored by hailey.at and committed by

GitHub 73d094c6 00a57df5

+18 -13
+18 -13
src/lib/media/manip.ts
··· 5 cacheDirectory, 6 copyAsync, 7 deleteAsync, 8 - documentDirectory, 9 EncodingType, 10 makeDirectoryAsync, 11 StorageAccessFramework, ··· 268 ) { 269 try { 270 if (isIOS) { 271 - const tmpFileUrl = await withTempFile(filename, encoded) 272 - await Sharing.shareAsync(tmpFileUrl, {UTI: type}) 273 - safeDeleteAsync(tmpFileUrl) 274 return true 275 } else { 276 const permissions = ··· 297 } 298 } 299 300 - async function withTempFile( 301 filename: string, 302 encoded: string, 303 - ): Promise<string> { 304 // Using a directory so that the file name is not a random string 305 - // documentDirectory will always be available on native, so we assert as a string. 306 - const tmpDirUri = joinPath(documentDirectory as string, String(uuid.v4())) 307 await makeDirectoryAsync(tmpDirUri, {intermediates: true}) 308 309 - const tmpFileUrl = joinPath(tmpDirUri, filename) 310 - await writeAsStringAsync(tmpFileUrl, encoded, { 311 - encoding: EncodingType.Base64, 312 - }) 313 - return tmpFileUrl 314 }
··· 5 cacheDirectory, 6 copyAsync, 7 deleteAsync, 8 EncodingType, 9 makeDirectoryAsync, 10 StorageAccessFramework, ··· 267 ) { 268 try { 269 if (isIOS) { 270 + await withTempFile(filename, encoded, async tmpFileUrl => { 271 + await Sharing.shareAsync(tmpFileUrl, {UTI: type}) 272 + }) 273 return true 274 } else { 275 const permissions = ··· 296 } 297 } 298 299 + async function withTempFile<T>( 300 filename: string, 301 encoded: string, 302 + cb: (url: string) => T | Promise<T>, 303 + ): Promise<T> { 304 + // cacheDirectory will not ever be null so we assert as a string. 305 // Using a directory so that the file name is not a random string 306 + const tmpDirUri = joinPath(cacheDirectory as string, String(uuid.v4())) 307 await makeDirectoryAsync(tmpDirUri, {intermediates: true}) 308 309 + try { 310 + const tmpFileUrl = joinPath(tmpDirUri, filename) 311 + await writeAsStringAsync(tmpFileUrl, encoded, { 312 + encoding: EncodingType.Base64, 313 + }) 314 + 315 + return await cb(tmpFileUrl) 316 + } finally { 317 + safeDeleteAsync(tmpDirUri) 318 + } 319 }