diff --git a/backup/9/Screen Recording 2023-03-23 at 11.04.39 PM.mov b/backup/9/Screen Recording 2023-03-23 at 11.04.39 PM.mov new file mode 100644 index 0000000..c4cea2a Binary files /dev/null and b/backup/9/Screen Recording 2023-03-23 at 11.04.39 PM.mov differ diff --git a/backup/9/Screen Recording 2023-03-24 at 1.43.01 PM.mov b/backup/9/Screen Recording 2023-03-24 at 1.43.01 PM.mov new file mode 100644 index 0000000..778a1d4 Binary files /dev/null and b/backup/9/Screen Recording 2023-03-24 at 1.43.01 PM.mov differ diff --git a/backup/9/Screen Recording 2023-03-26 at 8.29.13 PM.mov b/backup/9/Screen Recording 2023-03-26 at 8.29.13 PM.mov new file mode 100644 index 0000000..ef9ca72 Binary files /dev/null and b/backup/9/Screen Recording 2023-03-26 at 8.29.13 PM.mov differ diff --git a/public/9/1/1_1/test.docx b/public/9/1/1_1/test.docx new file mode 100644 index 0000000..2fb800c Binary files /dev/null and b/public/9/1/1_1/test.docx differ diff --git a/public/9/1/Screen Recording 2023-03-26 at 8.53.20 PM.mov b/public/9/1/Screen Recording 2023-03-26 at 8.53.20 PM.mov new file mode 100644 index 0000000..0fa8c55 Binary files /dev/null and b/public/9/1/Screen Recording 2023-03-26 at 8.53.20 PM.mov differ diff --git a/public/9/1/Screen Recording 2023-03-26 at 9.24.20 PM.mov b/public/9/1/Screen Recording 2023-03-26 at 9.24.20 PM.mov new file mode 100644 index 0000000..e1440b6 Binary files /dev/null and b/public/9/1/Screen Recording 2023-03-26 at 9.24.20 PM.mov differ diff --git a/public/9/1/Screen Recording 2023-03-26 at 9.27.55 PM.mov b/public/9/1/Screen Recording 2023-03-26 at 9.27.55 PM.mov new file mode 100644 index 0000000..48201e7 Binary files /dev/null and b/public/9/1/Screen Recording 2023-03-26 at 9.27.55 PM.mov differ diff --git a/public/9/1/Screen Recording 2023-03-29 at 9.59.01 AM.mov b/public/9/1/Screen Recording 2023-03-29 at 9.59.01 AM.mov new file mode 100644 index 0000000..40ad45d Binary files /dev/null and b/public/9/1/Screen Recording 2023-03-29 at 9.59.01 AM.mov differ diff --git a/public/9/1/Screen Shot 2022-12-20 at 5.34.40 PM.png b/public/9/1/Screen Shot 2022-12-20 at 5.34.40 PM.png new file mode 100644 index 0000000..3db7b74 Binary files /dev/null and b/public/9/1/Screen Shot 2022-12-20 at 5.34.40 PM.png differ diff --git a/public/9/1/Screen Shot 2022-12-20 at 5.35.27 PM.png b/public/9/1/Screen Shot 2022-12-20 at 5.35.27 PM.png new file mode 100644 index 0000000..102a772 Binary files /dev/null and b/public/9/1/Screen Shot 2022-12-20 at 5.35.27 PM.png differ diff --git a/public/9/1/Screen Shot 2022-12-20 at 5.36.02 PM.png b/public/9/1/Screen Shot 2022-12-20 at 5.36.02 PM.png new file mode 100644 index 0000000..d05bedb Binary files /dev/null and b/public/9/1/Screen Shot 2022-12-20 at 5.36.02 PM.png differ diff --git a/public/9/c1a875_e21d978198ad4b9c85cf63a8d1b146cc_mv2 (1).jpeg b/public/9/c1a875_e21d978198ad4b9c85cf63a8d1b146cc_mv2 (1).jpeg new file mode 100644 index 0000000..e18f2e3 Binary files /dev/null and b/public/9/c1a875_e21d978198ad4b9c85cf63a8d1b146cc_mv2 (1).jpeg differ diff --git a/public/9/c1a875_e75b8c21992e4f749fed9f2bfec29872_mv2 (1).png b/public/9/c1a875_e75b8c21992e4f749fed9f2bfec29872_mv2 (1).png new file mode 100644 index 0000000..a256d71 Binary files /dev/null and b/public/9/c1a875_e75b8c21992e4f749fed9f2bfec29872_mv2 (1).png differ diff --git a/public/9/c1a875_e75b8c21992e4f749fed9f2bfec29872_mv2 (2).png b/public/9/c1a875_e75b8c21992e4f749fed9f2bfec29872_mv2 (2).png new file mode 100644 index 0000000..a256d71 Binary files /dev/null and b/public/9/c1a875_e75b8c21992e4f749fed9f2bfec29872_mv2 (2).png differ diff --git a/public/9/coinbanner.jpeg b/public/9/coinbanner.jpeg new file mode 100644 index 0000000..a84ab26 Binary files /dev/null and b/public/9/coinbanner.jpeg differ diff --git a/public/9/test.docx b/public/9/test.docx new file mode 100644 index 0000000..2fb800c Binary files /dev/null and b/public/9/test.docx differ diff --git a/public/9/test/test1/test.docx b/public/9/test/test1/test.docx new file mode 100644 index 0000000..2fb800c Binary files /dev/null and b/public/9/test/test1/test.docx differ diff --git a/public/9/test1/test.docx b/public/9/test1/test.docx new file mode 100644 index 0000000..2fb800c Binary files /dev/null and b/public/9/test1/test.docx differ diff --git a/public/Stumble_Guys_0.47.3_3686_ff0525.apk b/public/Stumble_Guys_0.47.3_3686_ff0525.apk new file mode 100644 index 0000000..0f5aa89 Binary files /dev/null and b/public/Stumble_Guys_0.47.3_3686_ff0525.apk differ diff --git a/src/api/controllers/v1/image.controller.js b/src/api/controllers/v1/image.controller.js index 1045636..1e0da46 100644 --- a/src/api/controllers/v1/image.controller.js +++ b/src/api/controllers/v1/image.controller.js @@ -5,20 +5,19 @@ import Busboy from 'busboy'; import fs from 'fs-extra'; import multer from 'multer'; import httpStatus from 'http-status'; -import moment from 'moment-timezone'; +// import moment from 'moment-timezone'; import { handler as ErrorHandel } from '../../middlewares/errors'; import ApiException from '../../../common/utils/APIException'; -import eventBus from '../../../common/services/event-bus'; -import Image from '../../../common/models/image.model'; +// import eventBus from '../../../common/services/event-bus'; +// import Image from '../../../common/models/image.model'; import { cdn as cdnConfig, storage as storageConfig } from '../../../config/vars'; /** storage will create folder when new date */ -const date = new Date(); -const year = moment(date).format('YYYY'); -const month = moment(date).format('MM'); -const filePath = `${storageConfig.uri}/${year}/${month}/upload`; + + +const filePath = `${storageConfig.uri}`; const replaceBaseUrl = (location) => @@ -58,7 +57,7 @@ exports.uploadMultiple = (req, res, next) => { for (let index = 0; index < req.files.length; index += 1) { urls.push(replaceBaseUrl(req.files[index].path)); /** resize image uploaded */ - eventBus.emit(Image.Events.IMAGE_CREATED, req.files[index]); + // eventBus.emit(Image.Events.IMAGE_CREATED, req.files[index]); } return res.json({ urls: urls }); } catch (ex) { @@ -68,24 +67,30 @@ exports.uploadMultiple = (req, res, next) => { exports.uploadFile = (req, res, next) => { try { + console.log(req.query); let filename = null; - const cfg = { highWaterMark: 2097152 }; + const cfg = { highWaterMark: 1048576 * 2 }; // 20 mb cfg.headers = req.headers; req.busboy = Busboy(cfg); - multer({ dest: `${filePath}` }); + const pathName = `${filePath}/${req.query.path}`; + multer({ + dest: `${filePath}`, + limits: { + fileSize: 1024 * 1024 * 2048 // 2048MB + }, }); req.pipe(req.busboy); // Pipe it trough busboy return req.busboy.on('file', (name, file, info) => { filename = info.filename; - console.log('start', filename); + // Create a write stream of the new file - const fstream = fs.createWriteStream(path.join(filePath, filename)); + const fstream = fs.createWriteStream(path.join(pathName, filename)); // Pipe it trough file.pipe(fstream); // On finish of the upload fstream.on('close', () => { console.log(`Upload of '${filename}' finished`); - return res.json({ url: replaceBaseUrl(`${filePath}/${filename}`) }); + return res.json({ url: replaceBaseUrl(`${pathName}/${filename}`) }); }); }); } catch (ex) { diff --git a/src/api/controllers/v1/path.controller.js b/src/api/controllers/v1/path.controller.js index 577cd39..9170aa6 100644 --- a/src/api/controllers/v1/path.controller.js +++ b/src/api/controllers/v1/path.controller.js @@ -1,6 +1,6 @@ // import httpStatus from 'http-status'; import fs from 'fs'; - +import multer from 'multer'; import { handler as ErrorHandel } from '../../middlewares/errors'; // import ApiException from '../../../common/utils/APIException'; import { @@ -80,7 +80,7 @@ exports.update = (req, res, next) => { console.log(cdnConfig.uri, storageConfig.uri); const oldPath = req.body.oldPath.replace(cdnConfig.uri, storageConfig.uri); const newPath = req.body.newPath.replace(cdnConfig.uri, storageConfig.uri); - console.log('aaa', oldPath, newPath); + fs.rename(oldPath, newPath, (err) => { if (err) { console.log(err); @@ -97,11 +97,20 @@ exports.update = (req, res, next) => { exports.delete = (req, res, next) => { try { + const user = req.user; + const dir = `${storageConfig.uri_backup}/${user.id}`; + multer({ dest: `${dir}` }); const path = req.body.path.replace(cdnConfig.uri, storageConfig.uri); - fs.rm(path, { recursive: true }, err => { - if (err) { - return res.status(400).json({ code: 400, message: 'lỗi', detail: err }); - } + const newpath = req.body.path.replace(cdnConfig.uri, storageConfig.uri_backup); + console.log(path, newpath); + // fs.rm(path, { recursive: true }, err => { + // if (err) { + // return res.status(400).json({ code: 400, message: 'lỗi', detail: err }); + // } + // return res.json({ code: 0, message: 'success' }); + // }); + fs.rename(path, newpath, (err) => { + if (err) throw err; return res.json({ code: 0, message: 'success' }); }); return null; diff --git a/src/api/routes/v1/image.route.js b/src/api/routes/v1/image.route.js index 231d5bd..2e603eb 100644 --- a/src/api/routes/v1/image.route.js +++ b/src/api/routes/v1/image.route.js @@ -1,13 +1,13 @@ import express from 'express'; -import validate from 'express-validation'; +// import validate from 'express-validation'; // import { authorize } from '../../middlewares/auth.middleware'; // import Permissions from '../../../common/utils/Permissions'; import { uploader } from '../../../common/services/adapters/upload-adapter'; import controller from '../../controllers/v1/image.controller'; -import { - uploadValidation -} from '../../validations/v1/image.validation'; +// import { +// uploadValidation +// } from '../../validations/v1/image.validation'; const router = express.Router(); @@ -24,8 +24,8 @@ router .route('/upload-multiple') .post( // authorize([Permissions.IMAGE_UPLOAD]), - validate(uploadValidation), - uploader.array('file', 10), + // validate(uploadValidation), + uploader.array('file', 100), controller.uploadMultiple ); router diff --git a/src/common/services/adapters/upload-adapter.js b/src/common/services/adapters/upload-adapter.js index c6130ce..e294dea 100644 --- a/src/common/services/adapters/upload-adapter.js +++ b/src/common/services/adapters/upload-adapter.js @@ -63,12 +63,12 @@ const storage = multer.diskStorage({ * setup folder follow date */ createDefaultFolder({}); - + console.log('run in herer', req.query.path, file); /** * save image follow type */ const path = req.query.path; - console.log('path', path); + // const fileName = file.originalname.includes('.') // ? file.originalname.slice(0, file.originalname.lastIndexOf('.')) // : file.originalname; @@ -96,7 +96,7 @@ const fileFilter = (req, file, cb) => { const uploader = multer({ storage, limits: { - fileSize: 1024 * 1024 * 2 // 5MB + fileSize: 1024 * 1024 * 2048 // 5MB }, fileFilter }); diff --git a/src/config/locales/vi.json b/src/config/locales/vi.json index 1290eb6..4e82dc0 100644 --- a/src/config/locales/vi.json +++ b/src/config/locales/vi.json @@ -1,4 +1,7 @@ { "NOT_FOUND!": "NOT_FOUND!", - "Không tìm thấy tài khoản này!": "Không tìm thấy tài khoản này!" + "Không tìm thấy tài khoản này!": "Không tìm thấy tài khoản này!", + "Unexpected field": "Unexpected field", + "File too large": "File too large", + "Invalid file!": "Invalid file!" } \ No newline at end of file diff --git a/src/config/vars.js b/src/config/vars.js index 41e65ce..b38b8d3 100644 --- a/src/config/vars.js +++ b/src/config/vars.js @@ -18,7 +18,8 @@ module.exports = { uri: process.env.NODE_ENV === 'production' ? process.env.POSTGRES_URI : process.env.POSTGRES_URI_TEST }, storage: { - uri: process.env.NODE_ENV === 'production' ? process.env.STORAGE_URI : process.env.DEV_STORAGE_URI + uri: process.env.NODE_ENV === 'production' ? process.env.STORAGE_URI : process.env.DEV_STORAGE_URI, + uri_backup: process.env.NODE_ENV === 'production' ? process.env.STORAGE_BACKUP_URI : process.env.DEV_STORAGE_BACKUP_URI }, mongo: { uri: process.env.NODE_ENV === 'production' ? process.env.MONGO_URI : process.env.MONGO_URI_TEST