Skip to content

Commit 4121153

Browse files
committed
chore: consistant naming of Uri
1 parent 764ed7e commit 4121153

File tree

4 files changed

+18
-29
lines changed

4 files changed

+18
-29
lines changed

.changeset/polite-grapes-cover.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'@journeyapps/powersync-attachments': patch
33
---
44

5-
Change `AbstractAttachmentQueue` implementation to not save the full URI in the `attachments` table, instead create the full URI when needed.
5+
Change `AbstractAttachmentQueue` implementation to not save the full URI in the `attachments` table, instead create it when needed.

packages/powersync-attachments/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ export class AttachmentQueue extends AbstractAttachmentQueue {
160160
const photoAttachment = await this.newAttachmentRecord();
161161
photoAttachment.local_uri = this.getLocalFilePathSuffix(photoAttachment.filename);
162162

163-
const localFilePathURI = this.getLocalUri(photoAttachment.local_uri);
163+
const localFilePathUri = this.getLocalUri(photoAttachment.local_uri);
164164

165-
await this.storage.writeFile(localFilePathURI, base64Data, { encoding: 'base64' });
165+
await this.storage.writeFile(localFilePathUri, base64Data, { encoding: 'base64' });
166166

167167
return this.saveToQueue(photoAttachment);
168168
}

packages/powersync-attachments/src/AbstractAttachmentQueue.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
207207
await this.powersync.writeTransaction(deleteRecord);
208208
}
209209

210-
const localFilePathURI = this.getLocalUri(record.local_uri || this.getLocalFilePathSuffix(record.filename));
210+
const localFilePathUri = this.getLocalUri(record.local_uri || this.getLocalFilePathSuffix(record.filename));
211211

212212
try {
213213
// Delete file on storage
214-
await this.storage.deleteFile(localFilePathURI, {
214+
await this.storage.deleteFile(localFilePathUri, {
215215
filename: record.filename
216216
});
217217
} catch (e) {
@@ -238,9 +238,9 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
238238
throw new Error(`No local_uri for record ${JSON.stringify(record, null, 2)}`);
239239
}
240240

241-
const localFilePathURI = this.getLocalUri(record.local_uri);
241+
const localFilePathUri = this.getLocalUri(record.local_uri);
242242
try {
243-
if (!(await this.storage.fileExists(localFilePathURI))) {
243+
if (!(await this.storage.fileExists(localFilePathUri))) {
244244
console.warn(`File for ${record.id} does not exist, skipping upload`);
245245
await this.update({
246246
...record,
@@ -249,7 +249,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
249249
return true;
250250
}
251251

252-
const fileBuffer = await this.storage.readFile(localFilePathURI, {
252+
const fileBuffer = await this.storage.readFile(localFilePathUri, {
253253
encoding: EncodingType.Base64,
254254
mediaType: record.media_type
255255
});
@@ -276,8 +276,8 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
276276
if (!record.local_uri) {
277277
record.local_uri = this.getLocalFilePathSuffix(record.filename);
278278
}
279-
const localFilePathURI = this.getLocalUri(record.local_uri);
280-
if (await this.storage.fileExists(localFilePathURI)) {
279+
const localFilePathUri = this.getLocalUri(record.local_uri);
280+
if (await this.storage.fileExists(localFilePathUri)) {
281281
console.debug(`Local file already downloaded, marking "${record.id}" as synced`);
282282
await this.update({ ...record, state: AttachmentState.SYNCED });
283283
return true;
@@ -298,9 +298,9 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
298298
});
299299

300300
// Ensure directory exists
301-
await this.storage.makeDir(localFilePathURI.replace(record.filename, ''));
301+
await this.storage.makeDir(localFilePathUri.replace(record.filename, ''));
302302
// Write the file
303-
await this.storage.writeFile(localFilePathURI, base64Data, {
303+
await this.storage.writeFile(localFilePathUri, base64Data, {
304304
encoding: EncodingType.Base64
305305
});
306306

packages/powersync-attachments/src/StorageAdapter.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
export enum EncodingType {
2-
UTF8 = "utf8",
3-
Base64 = "base64",
2+
UTF8 = 'utf8',
3+
Base64 = 'base64'
44
}
55

66
export interface StorageAdapter {
7-
uploadFile(
8-
filePath: string,
9-
data: ArrayBuffer,
10-
options?: { mediaType?: string }
11-
): Promise<void>;
7+
uploadFile(filePath: string, data: ArrayBuffer, options?: { mediaType?: string }): Promise<void>;
128

139
downloadFile(filePath: string): Promise<Blob>;
1410

15-
writeFile(
16-
fileURI: string,
17-
base64Data: string,
18-
options?: { encoding?: EncodingType }
19-
): Promise<void>;
11+
writeFile(fileUri: string, base64Data: string, options?: { encoding?: EncodingType }): Promise<void>;
2012

21-
readFile(
22-
fileURI: string,
23-
options?: { encoding?: EncodingType; mediaType?: string }
24-
): Promise<ArrayBuffer>;
13+
readFile(fileUri: string, options?: { encoding?: EncodingType; mediaType?: string }): Promise<ArrayBuffer>;
2514

2615
deleteFile(uri: string, options?: { filename?: string }): Promise<void>;
2716

28-
fileExists(fileURI: string): Promise<boolean>;
17+
fileExists(fileUri: string): Promise<boolean>;
2918

3019
makeDir(uri: string): Promise<void>;
3120

0 commit comments

Comments
 (0)