Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/drivers/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ export class Local implements StorageDriver {
*
* @param path
*/
url(fileName: string) {
url(path: string) {
if (this.config.hasOwnProperty("baseUrl")) {
const filePath = join("public", fileName);
return `${this.config.basePath}/${filePath}`;
const normalizedPath = path.replace(/\\/g, "/");
return `${this.config.baseUrl}/${normalizedPath}`;
} else {
return "";
}
Expand Down
1 change: 1 addition & 0 deletions lib/interfaces/storageOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface DiskOptions {
accessKey?: string;
secretKey?: string;
fetchRemoteCredentials?: boolean;
baseUrl?: string;
}

export interface StorageOptions {
Expand Down
21 changes: 12 additions & 9 deletions lib/storage.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import {
StorageOptionsFactory,
} from './interfaces';
import { map } from './provider.map';
import { Storage } from './storage';

@Module({
providers: [],
exports: [],
})
@Module({})
export class StorageModule {
static register(options: StorageOptions): DynamicModule {
return {
Expand All @@ -24,18 +20,24 @@ export class StorageModule {
useValue: options,
},
],
exports: [StorageService],
};
}

static registerAsync(options: StorageAsyncOptions): DynamicModule {
return {
global: true,
module: StorageModule,
providers: [this.createStorageOptionsProvider(options), StorageService],
imports: options.imports || [],
providers: [
StorageService,
this.createAsyncOptionsProvider(options),
],
exports: [StorageService],
};
}

private static createStorageOptionsProvider(
private static createAsyncOptionsProvider(
options: StorageAsyncOptions,
): Provider {
if (options.useFactory) {
Expand All @@ -47,13 +49,14 @@ export class StorageModule {
}

const inject = [
(options.useClass || options.useExisting) as Type<StorageOptions>,
(options.useClass || options.useExisting) as unknown as Type<StorageOptionsFactory>,
];

return {
provide: map.STORAGE_OPTIONS,
useFactory: async (optionsFactory: StorageOptionsFactory) =>
await optionsFactory.createStorageOptions(),
inject,
};
}
}
}
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@squareboat/nest-storage",
"version": "0.1.6",
"name": "@kshiro/nest-storage",
"version": "0.0.6",
"description": "Multi disk multi driver storage manager for NestJS 💿💾",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -11,7 +11,7 @@
],
"repository": {
"type": "git",
"url": "https://github.com/squareboat/nestjs-storage.git"
"url": "git+https://github.com/squareboat/nestjs-storage.git"
},
"bugs": {
"url": "https://github.com/squareboat/nestjs-storage/issues"
Expand Down Expand Up @@ -45,5 +45,8 @@
"peerDependencies": {
"@nestjs/common": "^6.7.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0",
"@nestjs/core": "^6.7.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0"
},
"directories": {
"lib": "lib"
}
}
}