Compare commits

..

No commits in common. 'def83939c761a7f1a2a76c9d73f47786a3dbe627' and '728c7eed23d5fb02bba7c0acf588bca58096009f' have entirely different histories.

  1. 0
      public/15/name name/file.txt
  2. 0
      public/15/namename/file.txt
  3. BIN
      public/download/15/123353222-1684321000419.zip
  4. 61
      src/api/controllers/v1/path.controller.js
  5. 4
      src/api/controllers/v1/staff.controller.js
  6. 14
      src/api/middlewares/path.middleware.js
  7. 4
      src/api/validations/v1/staff.validation.js
  8. 5
      src/common/services/adapters/upload-adapter.js
  9. 9
      src/config/locales/en.json

@ -12,8 +12,6 @@ import {
storage as storageConfig
} from '../../../config/vars';
import uploadAdapter from '../../../common/services/adapters/upload-adapter';
import { cloneDeep, forEach } from 'lodash';
/**
* get file and folder
@ -25,11 +23,12 @@ exports.get = (req, res, next) => {
const user = req.user;
let path = `${storageConfig.uri}/${user.id}`;
// let path = storageConfig.uri;
if (req.body.path) {
path += req.body.path;
}
// console.log(path);
const listFile = [];
fs.readdir(path, (err, files) => {
if (files && files.length > 0) {
files.forEach((item) => {
@ -45,24 +44,6 @@ exports.get = (req, res, next) => {
data: listFile
});
});
// test local
// fs.readdir(path, (err, files) => {
// if (files && files.length > 0) {
// files.forEach((item) => {
// listFile.push({
// name: item,
// path: `${storageConfig.uri}/${user.id}${req.body.path}/${item}`,
// isFolder: fs.lstatSync(`${storageConfig.uri}/${user.id}/${req.body.path}/${item}`).isDirectory()
// });
// });
// }
// return res.json({
// code: 0,
// data: listFile
// });
// });
return null;
/** resize image uploaded */
} catch (ex) {
@ -77,18 +58,19 @@ exports.get = (req, res, next) => {
*/
exports.create = (req, res, next) => {
const user = req.user;
let dir = `${user.id}`;
const name_folder = cloneDeep(req.body.name).trim();
console.log(dir);
if (req.body.path) {
dir += req.body.path;
}
if (req.body.name) {
dir += `/${name_folder}`;
dir += `/${req.body.name}`;
}
if (!fs.existsSync(dir)) {
uploadAdapter.createFolder({ path: dir });
}
return res.json({ code: 0, message: 'success'});
return res.json({ code: 0, message: 'success' });
};
/**
@ -141,24 +123,16 @@ exports.download = (req, res, next) => {
try {
const user = req.user;
const namefile = `${user.name}-${Date.now()}.zip`;
const dir = `${storageConfig.uri}/download/${user.id}/${namefile}`;
const folder = `${storageConfig.uri}/download/${user.id}`;
deleteFolderRecursive(folder);
const dir = `${storageConfig.uri}/${user.id}/${namefile}`;
const output = fs.createWriteStream(dir);
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
archive.pipe(output);
if (req.body.data) {
req.body.data.forEach((e) => {
// const path = e.path.replace(cdnConfig.uri, storageConfig.uri).replace(/ /g, '%20');
const path = e.path.replace(cdnConfig.uri, storageConfig.uri);
// const download = path.split("/");
// download.splice( download.indexOf(`${user.id}`), 0, "download");
// const final_path = download.join("/");
const path = e.path.replace(cdnConfig.uri, storageConfig.uri).replace(/ /g, '%20');
if (e.isFolder) {
archive.directory(path, e.name);
} else {
@ -167,6 +141,7 @@ exports.download = (req, res, next) => {
});
}
archive.finalize();
return res.json({
code: 0,
data: {
@ -219,21 +194,3 @@ exports.deleteMultiple = (req, res, next) => {
return ErrorHandel(ex, req, res, next);
}
};
function deleteFolderRecursive(folderPath) {
let files = [];
if (fs.existsSync(folderPath)) {
files = fs.readdirSync(folderPath);
files.forEach((file) => {
const currentPath = path.join(folderPath, file);
if (fs.lstatSync(currentPath).isDirectory()) {
deleteFolderRecursive(currentPath);
} else {
fs.unlinkSync(currentPath);
console.log('Deleted file:', currentPath);
}
});
}
}

@ -84,7 +84,7 @@ exports.get = async (req, res, next) => res.json({ data: User.transform(req.loca
*/
exports.update = async (req, res, next) => {
const { user } = req.locals;
if (user.service !== "staff") {
if (user.service !== "service") {
return res.status(404).json({
code: 404,
message : messages.NOT_FOUND
@ -117,7 +117,7 @@ exports.update = async (req, res, next) => {
*/
exports.delete = async (req, res, next) => {
const { user } = req.locals;
if (user.service !== "staff") {
if (user.service !== "service") {
return res.status(404).json({
code: 404,
message : messages.NOT_FOUND

@ -1,14 +0,0 @@
import { handler as ErrorHandler } from './errors';
import fs from 'fs';
import archiver from 'archiver';
import multer from 'multer';
import path from 'path';
import { handler as ErrorHandel } from '../../middlewares/errors';
// import ApiException from '../../../common/utils/APIException';
import {
cdn as cdnConfig,
storage as storageConfig
} from '../../../config/vars';
import uploadAdapter from '../../../common/services/adapters/upload-adapter';

@ -55,8 +55,8 @@ module.exports = {
.max(255)
.required(),
phone: Joi.string()
.max(155),
// .required(),
.max(155)
.required(),
email: Joi.string()
.allow(null, ''),
gender: Joi.string()

@ -1,8 +1,6 @@
import multer from 'multer';
// import moment from 'moment-timezone';
import { storage as storageConfig } from '../../../config/vars';
import { forIn } from 'lodash';
import { equal } from 'joi';
/** storage will create folder when new date */
// const date = new Date();
@ -38,8 +36,6 @@ const createFolder = ({ path }) => {
try {
console.log(`${filePath}/${path}`);
multer({ dest: `${filePath}/${path}` });
// multer({ dest: `${filePath}/images/games` });
// multer({ dest: `${filePath}/images/stories` });
// multer({ dest: `${filePath}/images/chapters` });
@ -52,7 +48,6 @@ const createFolder = ({ path }) => {
// multer({ dest: `${filePath}/images/banners` });
// multer({ dest: `${filePath}/images/categories` });
// multer({ dest: `${filePath}/images/upload/default` });
// console.log(multer);
return true;
} catch (ex) {
return false;

@ -28,12 +28,5 @@
"log is not defined": "log is not defined",
"connect ETIMEDOUT 113.177.27.200:5432": "connect ETIMEDOUT 113.177.27.200:5432",
"Validation error: Validation isEmail on email failed": "Validation error: Validation isEmail on email failed",
"WHERE parameter \"id\" has invalid \"undefined\" value": "WHERE parameter \"id\" has invalid \"undefined\" value",
"blank is not defined": "blank is not defined",
"equal is not defined": "equal is not defined",
"isEqual is not defined": "isEqual is not defined",
"_ is not defined": "_ is not defined",
"Cannot access 'splited_dir' before initialization": "Cannot access 'splited_dir' before initialization",
"main_dir is not defined": "main_dir is not defined",
"Cannot read properties of undefined (reading 'trim')": "Cannot read properties of undefined (reading 'trim')"
"WHERE parameter \"id\" has invalid \"undefined\" value": "WHERE parameter \"id\" has invalid \"undefined\" value"
}
Loading…
Cancel
Save