Skip to content

Commit

Permalink
[accel-wave] add url to Storage intarface
Browse files Browse the repository at this point in the history
  • Loading branch information
koyopro committed Dec 21, 2024
1 parent b3904c0 commit c4fd57c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
8 changes: 3 additions & 5 deletions packages/accel-wave/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ export class BaseUploader {
}

url() {
if (!this.file) return undefined;
if (!this.filename) return undefined;

if (this.config.assetHost) {
return new URL(`${this.config.storeDir}/${this.filename}`, this.config.assetHost);
} else {
return new URL(
`${this.config.root}/${this.config.storeDir}/${this.filename}`,
import.meta.url
);
return this.storage.url(this.filename);
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/accel-wave/src/storages/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ export class FileStorage implements Storage {
).pathname;
return new File([fs.readFileSync(filePath)], identifier);

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

tests/models/columns.test.ts > Columns > enum column

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:573:18 ❯ Object.readFileSync node:fs:452:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ tests/models/columns.test.ts:54:23 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

tests/models/dbMapping.test.ts > database mapping > mapping table name, default values

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:573:18 ❯ Object.readFileSync node:fs:452:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Proxy.update packages/accel-record-core/dist/persistence.js:82:21 ❯ tests/models/dbMapping.test.ts:21:13 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

tests/models/queryMapping.test.ts > Query with DB mappings > select

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:573:18 ❯ Object.readFileSync node:fs:452:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ tests/models/queryMapping.test.ts:24:13 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

tests/wave/mount.test.ts > mount

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:573:18 ❯ Object.readFileSync node:fs:452:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ Object.create packages/accel-record-factory/dist/index.js:21:26 ❯ tests/wave/mount.test.ts:7:25 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

tests/models/model/callbacks.test.ts > create callbacks

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:573:18 ❯ Object.readFileSync node:fs:452:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ Object.create packages/accel-record-factory/dist/index.js:21:26 ❯ tests/models/model/callbacks.test.ts:14:28 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

tests/models/model/callbacks.test.ts > update callbacks

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:573:18 ❯ Object.readFileSync node:fs:452:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ Object.create packages/accel-record-factory/dist/index.js:21:26 ❯ tests/models/model/callbacks.test.ts:26:28 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

tests/models/model/callbacks.test.ts > destroy callbacks

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:573:18 ❯ Object.readFileSync node:fs:452:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ Object.create packages/accel-record-factory/dist/index.js:21:26 ❯ tests/models/model/callbacks.test.ts:40:28 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

tests/models/columns.test.ts > Columns > enum column

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:561:18 ❯ Object.readFileSync node:fs:445:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ tests/models/columns.test.ts:54:23 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

tests/models/dbMapping.test.ts > database mapping > mapping table name, default values

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:561:18 ❯ Object.readFileSync node:fs:445:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Proxy.update packages/accel-record-core/dist/persistence.js:82:21 ❯ tests/models/dbMapping.test.ts:21:13 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

tests/models/queryMapping.test.ts > Query with DB mappings > select

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:561:18 ❯ Object.readFileSync node:fs:445:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ tests/models/queryMapping.test.ts:24:13 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

tests/wave/mount.test.ts > mount

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:561:18 ❯ Object.readFileSync node:fs:445:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ Object.create packages/accel-record-factory/dist/index.js:21:26 ❯ tests/wave/mount.test.ts:7:25 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

tests/models/model/callbacks.test.ts > create callbacks

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:561:18 ❯ Object.readFileSync node:fs:445:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ Object.create packages/accel-record-factory/dist/index.js:21:26 ❯ tests/models/model/callbacks.test.ts:14:28 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

tests/models/model/callbacks.test.ts > update callbacks

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:561:18 ❯ Object.readFileSync node:fs:445:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ Object.create packages/accel-record-factory/dist/index.js:21:26 ❯ tests/models/model/callbacks.test.ts:26:28 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }

Check failure on line 22 in packages/accel-wave/src/storages/file.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

tests/models/model/callbacks.test.ts > destroy callbacks

Error: ENOENT: no such file or directory, open '/home/runner/work/accella/accella/public/uploads/undefined' ❯ Object.openSync node:fs:561:18 ❯ Object.readFileSync node:fs:445:35 ❯ FileStorage.retrive packages/accel-wave/src/storages/file.ts:22:25 ❯ BaseUploader.get file [as file] packages/accel-wave/src/index.ts:33:41 ❯ Proxy.<anonymous> packages/accel-wave/src/index.ts:9:18 ❯ Proxy.runBeforeCallbacks packages/accel-record-core/dist/callbacks.js:49:16 ❯ Proxy.save packages/accel-record-core/dist/persistence.js:65:14 ❯ Function.create packages/accel-record-core/dist/persistence.js:29:22 ❯ Object.create packages/accel-record-factory/dist/index.js:21:26 ❯ tests/models/model/callbacks.test.ts:40:28 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/accella/accella/public/uploads/undefined' }
}

url(identifier: string) {
return new URL(`${this.config.root}/${this.config.storeDir}/${identifier}`, import.meta.url);
}
}
1 change: 1 addition & 0 deletions packages/accel-wave/src/storages/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface Storage {
store(file: File): void;
retrive(identifier: string): File;
url(identifier: string): URL;
}
3 changes: 2 additions & 1 deletion packages/accel-wave/src/storages/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ export class S3Storage implements Storage {
const config = this.config.s3;
if (!config) throw new Error("S3 config is not set");

return actions.getSignedS3Url(
const url = actions.getSignedS3Url(
{ region: config.region },
{
Bucket: config.bucket,
Key: identifier,
}
);
return new URL(url);
}
}
4 changes: 3 additions & 1 deletion packages/accel-wave/tests/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Config, configureAccelWave } from "src/config";
import { S3Storage } from "src/storages/s3";

test("initAccelWave()", () => {
configureAccelWave({ storeDir: "test", s3: { region: "ap-northeast-1" } });
configureAccelWave({ storage: S3Storage, storeDir: "test", s3: { region: "ap-northeast-1" } });

const config = new Config({ s3: { bucket: "test2" } });

expect(config.storage).toEqual(S3Storage);
expect(config.storeDir).toBe("test");
expect(config.s3).toMatchObject({ region: "ap-northeast-1", bucket: "test2" });
});
18 changes: 18 additions & 0 deletions packages/accel-wave/tests/s3Storage.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { config } from "dotenv";
import { Config } from "src/config";
import { BaseUploader } from "src/index";
import { S3Storage } from "../src/storages/s3";
import { buildFile } from "./buildFile";

Expand Down Expand Up @@ -27,3 +28,20 @@ test("store()", (context: any) => {
)
);
});

test("S3Storage with Uploader", () => {
const region = process.env.AWS_REGION;
const bucket = process.env.AWS_S3_BUCKET;
if (!region || !bucket) return;

const uploader = new BaseUploader({
storage: S3Storage,
s3: { region, bucket },
filename: "example.txt",
});
expect(uploader.url()).toMatch(
new RegExp(
`https://${bucket}.s3.${region}.amazonaws.com/example.txt\\?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=.+`
)
);
});

0 comments on commit c4fd57c

Please sign in to comment.