Skip to content

Commit

Permalink
Removes datadrive
Browse files Browse the repository at this point in the history
  • Loading branch information
maasencioh committed Jul 6, 2020
1 parent 9c2bdaa commit 8fd8e3f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 51 deletions.
6 changes: 1 addition & 5 deletions .adonisrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"Database": "database"
},
"preloads": ["./start/routes", "./start/kernel"],
"providers": [
"./providers/AppProvider",
"@adonisjs/core",
"adonis-datadrive"
],
"providers": ["./providers/AppProvider", "@adonisjs/core"],
"metaFiles": [".env", ".adonisrc.json"]
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ coverage
.vscode
.DS_STORE
.env
tmp
tmp

data
30 changes: 24 additions & 6 deletions app/Controllers/Http/FilesController.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
import DataDrive from '@ioc:DataDrive';
import { StorageManager, LocalFileSystemStorage } from '@slynova/flydrive';

const storageConfig = {
default: 'local',
disks: {
local: { driver: 'local', config: { root: `${process.cwd()}/data` } },

s3: {
driver: 's3',
config: {
key: 'AWS_S3_KEY',
secret: 'AWS_S3_SECRET',
region: 'AWS_S3_REGION',
bucket: 'AWS_S3_BUCKET',
},
},
},
};

export default class FilesController {
private dataPath = './data';
private storage = new StorageManager(storageConfig).disk<
LocalFileSystemStorage
>('local');

public async upload({ request, params }: HttpContextContract) {
if (!request.hasValidSignature()) return { error: 'url not valid' };

const { filename } = params;
if (!filename) return { error: 'filename is required' };

request.multipart.onFile(filename, {}, async (file) => {
await DataDrive.drive(this.dataPath).put(filename, file);
await this.storage.put(filename, file);
});
await request.multipart.process();

Expand All @@ -24,8 +42,8 @@ export default class FilesController {
const { filename } = params;
if (!filename) return { error: 'filename is required' };

const file = await DataDrive.drive(this.dataPath).get(filename);
const file = await this.storage.get(filename);
if (!file) return { error: `file ${filename} not founded` };
return { data: file };
return file;
}
}
15 changes: 0 additions & 15 deletions config/datadrive.ts

This file was deleted.

22 changes: 0 additions & 22 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@adonisjs/ace": "~6.9.3",
"@adonisjs/core": "~5.0.0-preview-rc-1.9",
"@adonisjs/fold": "~6.3.5",
"adonis-datadrive": "~0.1.1",
"@slynova/flydrive": "~1.0.1",
"proxy-addr": "~2.0.6",
"reflect-metadata": "~0.1.13",
"source-map-support": "~0.5.19"
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"Contracts/*": ["./contracts/*"],
"Database/*": ["./database/*"]
},
"types": ["@adonisjs/core", "adonis-datadrive"]
"types": ["@adonisjs/core"]
}
}

0 comments on commit 8fd8e3f

Please sign in to comment.