@veap/storage 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/provider.js +9 -2
- package/dist/providers/local.d.ts +1 -1
- package/dist/providers/local.js +6 -4
- package/dist/storage.service.d.ts +5 -4
- package/dist/storage.service.js +3 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.js +1 -1
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
[](https://github.com/veapjs/veap-storage/actions/workflows/CI.yml)
|
|
2
|
+
[](https://github.com/veapjs/veap-storage/actions/workflows/RELEASE.yml)
|
|
3
|
+
[](https://www.npmjs.com/package/@veap/storage)
|
|
3
4
|
|
|
4
5
|
# @veap/storage
|
|
5
6
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./provider";
|
|
2
|
-
export * from "./providers/local";
|
|
3
|
-
export * from "./storage.service";
|
|
4
|
-
export * from "./types";
|
|
1
|
+
export * from "./provider.js";
|
|
2
|
+
export * from "./providers/local.js";
|
|
3
|
+
export * from "./storage.service.js";
|
|
4
|
+
export * from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./provider";
|
|
2
|
-
export * from "./providers/local";
|
|
3
|
-
export * from "./storage.service";
|
|
4
|
-
export * from "./types";
|
|
1
|
+
export * from "./provider.js";
|
|
2
|
+
export * from "./providers/local.js";
|
|
3
|
+
export * from "./storage.service.js";
|
|
4
|
+
export * from "./types.js";
|
package/dist/provider.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ConfigService, ServiceProvider } from "@veap/kernel";
|
|
2
|
-
import { LocalFileProvider } from "./providers/local";
|
|
3
|
-
import { StorageService } from "./storage.service";
|
|
2
|
+
import { LocalFileProvider } from "./providers/local.js";
|
|
3
|
+
import { StorageService } from "./storage.service.js";
|
|
4
|
+
import { STORAGE_SERVICE } from "./types.js";
|
|
4
5
|
export class StorageServiceProvider extends ServiceProvider {
|
|
5
6
|
register() {
|
|
6
7
|
this.container.register({
|
|
@@ -8,6 +9,12 @@ export class StorageServiceProvider extends ServiceProvider {
|
|
|
8
9
|
useClass: StorageService,
|
|
9
10
|
singleton: true,
|
|
10
11
|
});
|
|
12
|
+
this.container.register({
|
|
13
|
+
token: STORAGE_SERVICE,
|
|
14
|
+
useFactory: (service) => service,
|
|
15
|
+
inject: [StorageService],
|
|
16
|
+
singleton: true,
|
|
17
|
+
});
|
|
11
18
|
}
|
|
12
19
|
async boot() {
|
|
13
20
|
const storageService = await this.container.resolve(StorageService);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ConfigService } from "@veap/kernel";
|
|
2
|
-
import type { IStorageProvider, StorageResult } from "../types";
|
|
2
|
+
import type { IStorageProvider, StorageResult } from "../types.js";
|
|
3
3
|
export declare class LocalFileProvider implements IStorageProvider {
|
|
4
4
|
private config;
|
|
5
5
|
id: string;
|
package/dist/providers/local.js
CHANGED
|
@@ -75,15 +75,17 @@ export class LocalFileProvider {
|
|
|
75
75
|
}
|
|
76
76
|
const storageFolder = this.getStorageFolder();
|
|
77
77
|
if (!fs.existsSync(/*turbopackIgnore: true*/ storageFolder)) {
|
|
78
|
-
fs.
|
|
78
|
+
await fs.promises.mkdir(/*turbopackIgnore: true*/ storageFolder, {
|
|
79
79
|
recursive: true,
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
const name = this.generateUniqueImageName(rawName);
|
|
83
83
|
const filePath = path.join(/*turbopackIgnore: true*/ storageFolder, name);
|
|
84
84
|
const buffer = await file.arrayBuffer();
|
|
85
|
-
fs.
|
|
86
|
-
|
|
85
|
+
await fs.promises.writeFile(
|
|
86
|
+
/*turbopackIgnore: true*/ filePath, Buffer.from(buffer));
|
|
87
|
+
const rawUrl = `${storageFolder}/${name}`.replace("public", "");
|
|
88
|
+
const url = rawUrl.startsWith("/") ? rawUrl : `/${rawUrl}`;
|
|
87
89
|
return {
|
|
88
90
|
name: name,
|
|
89
91
|
url,
|
|
@@ -127,7 +129,7 @@ export class LocalFileProvider {
|
|
|
127
129
|
return false;
|
|
128
130
|
}
|
|
129
131
|
if (fs.existsSync(/*turbopackIgnore: true*/ absolutePath)) {
|
|
130
|
-
fs.
|
|
132
|
+
await fs.promises.unlink(/*turbopackIgnore: true*/ absolutePath);
|
|
131
133
|
return true;
|
|
132
134
|
}
|
|
133
135
|
return false;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ILogger } from "@veap/kernel";
|
|
2
|
-
import type { IStorageProvider, StorageResult } from "./types";
|
|
3
|
-
export declare class StorageService {
|
|
2
|
+
import type { IStorageProvider, IStorageService, StorageResult } from "./types.js";
|
|
3
|
+
export declare class StorageService implements IStorageService {
|
|
4
4
|
private providers;
|
|
5
5
|
private defaultProviderId;
|
|
6
6
|
private logger;
|
|
@@ -8,10 +8,11 @@ export declare class StorageService {
|
|
|
8
8
|
registerProvider(provider: IStorageProvider): void;
|
|
9
9
|
unregisterProvider(id: string): void;
|
|
10
10
|
setDefaultProvider(id: string): void;
|
|
11
|
+
getDefaultProviderId(): string | null;
|
|
11
12
|
upload(file: File, providerId?: string): Promise<StorageResult>;
|
|
12
13
|
delete(keyOrUrl: string, providerId?: string): Promise<boolean>;
|
|
13
|
-
getProviders(): {
|
|
14
|
+
getProviders(): Array<{
|
|
14
15
|
id: string;
|
|
15
16
|
name: string;
|
|
16
|
-
}
|
|
17
|
+
}>;
|
|
17
18
|
}
|
package/dist/storage.service.js
CHANGED
|
@@ -40,6 +40,9 @@ let StorageService = class StorageService {
|
|
|
40
40
|
this.logger.info("veap:storage", `Default provider set to: ${id}`);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
getDefaultProviderId() {
|
|
44
|
+
return this.defaultProviderId;
|
|
45
|
+
}
|
|
43
46
|
async upload(file, providerId) {
|
|
44
47
|
let id = providerId || this.defaultProviderId;
|
|
45
48
|
if (!id || !this.providers.has(id)) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Token } from "@veap/kernel";
|
|
1
2
|
export interface StorageData {
|
|
2
3
|
name: string;
|
|
3
4
|
url: string;
|
|
@@ -16,3 +17,16 @@ export interface IStorageProvider {
|
|
|
16
17
|
upload(file: File, options?: any): Promise<StorageResult>;
|
|
17
18
|
delete?(serviceId: string): Promise<boolean>;
|
|
18
19
|
}
|
|
20
|
+
export interface IStorageService {
|
|
21
|
+
registerProvider(provider: IStorageProvider): void;
|
|
22
|
+
unregisterProvider(id: string): void;
|
|
23
|
+
setDefaultProvider(id: string): void;
|
|
24
|
+
getDefaultProviderId(): string | null;
|
|
25
|
+
upload(file: File, providerId?: string): Promise<StorageResult>;
|
|
26
|
+
delete(keyOrUrl: string, providerId?: string): Promise<boolean>;
|
|
27
|
+
getProviders(): Array<{
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
export declare const STORAGE_SERVICE: Token<IStorageService>;
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const STORAGE_SERVICE = Symbol.for("veap:storage:service");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veap/storage",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "File storage service and local driver for Veap",
|
|
5
5
|
"bugs": "https://github.com/veapjs/veap-storage/issues",
|
|
6
6
|
"repository": {
|
|
@@ -16,6 +16,14 @@
|
|
|
16
16
|
"types": "./dist/index.d.ts",
|
|
17
17
|
"default": "./dist/index.js"
|
|
18
18
|
},
|
|
19
|
+
"./providers/local": {
|
|
20
|
+
"types": "./dist/providers/local.d.ts",
|
|
21
|
+
"default": "./dist/providers/local.js"
|
|
22
|
+
},
|
|
23
|
+
"./types": {
|
|
24
|
+
"types": "./dist/types.d.ts",
|
|
25
|
+
"default": "./dist/types.js"
|
|
26
|
+
},
|
|
19
27
|
"./package.json": "./package.json"
|
|
20
28
|
},
|
|
21
29
|
"files": [
|
|
@@ -28,7 +36,7 @@
|
|
|
28
36
|
"test": "vitest run"
|
|
29
37
|
},
|
|
30
38
|
"dependencies": {
|
|
31
|
-
"@veap/kernel": "0.1.
|
|
39
|
+
"@veap/kernel": "0.1.2"
|
|
32
40
|
},
|
|
33
41
|
"devDependencies": {
|
|
34
42
|
"@types/node": "^22.20.2",
|