-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom upload provider to fix the EXDEV error.
- Loading branch information
1 parent
284277a
commit 7faee8c
Showing
6 changed files
with
87 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import { move } from 'fs-extra'; | ||
import { UploadedFile } from 'adminjs'; | ||
import { BaseProvider } from '@adminjs/upload'; | ||
|
||
export default class UploadProvider extends BaseProvider { | ||
// * Fixed this method because original does rename instead of move and it doesn't work with docker volume | ||
public async upload(file: UploadedFile, key: string): Promise<any> { | ||
// adjusting file path according to OS | ||
const filePath = process.platform === 'win32' ? this.path(key) : this.path(key).slice(1); | ||
await fs.promises.mkdir(path.dirname(filePath), { recursive: true }); | ||
await move(file.path, filePath, { overwrite: true }); | ||
} | ||
|
||
public async delete(key: string, bucket: string): Promise<any> { | ||
// adjusting file path according to OS | ||
await fs.promises.unlink(process.platform === 'win32' ? this.path(key, bucket) : this.path(key, bucket).slice(1)); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
public path(key: string, bucket?: string): string { | ||
// Windows doesn't requires the '/' in path, while UNIX system does | ||
return process.platform === 'win32' | ||
? `${path.join(bucket || this.bucket, key)}` | ||
: `/${path.join(bucket || this.bucket, key)}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters