-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(backend): create avatar - upload and update
- Loading branch information
João Paulo
committed
May 12, 2020
1 parent
17dd756
commit 54ddbd1
Showing
10 changed files
with
253 additions
and
6 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.DS_* | ||
/node_modules | ||
/dist | ||
/dist | ||
/tmp/* | ||
!/tmp/.gitkeep |
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,19 @@ | ||
import path from 'path'; | ||
import crypto from 'crypto'; | ||
import multer from 'multer'; | ||
|
||
const tmpFolder = path.resolve(__dirname, '..', '..', 'tmp'); | ||
|
||
export default { | ||
directory: tmpFolder, | ||
|
||
storage: multer.diskStorage({ | ||
destination: tmpFolder, | ||
filename(request, file, callback) { | ||
const fileHash = crypto.randomBytes(10).toString('HEX'); | ||
const fileName = `${fileHash}-${file.originalname}`; | ||
|
||
return callback(null, fileName); | ||
}, | ||
}), | ||
}; |
19 changes: 19 additions & 0 deletions
19
backend/src/database/migrations/1589247025644-AddAvatarFieldToUser.ts
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,19 @@ | ||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm'; | ||
|
||
export default class AddAvatarFieldToUser1589247025644 | ||
implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.addColumn( | ||
'users', | ||
new TableColumn({ | ||
name: 'avatar', | ||
type: 'varchar', | ||
isNullable: true, | ||
}), | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropColumn('users', 'avatar'); | ||
} | ||
} |
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
Oops, something went wrong.