Add new file database, count how many times its downloaded

tungd0 1 year ago
commit c8dc7a9507
  1. 1
      src/api/controllers/v1/path.controller.js
  2. 117
      src/common/services/adapters/upload-adapter.js

@ -357,3 +357,4 @@ exports.deleteMultiple = (req, res, next) => {
}; };

@ -1,3 +1,4 @@
<<<<<<< HEAD
import multer from 'multer'; import multer from 'multer';
// import moment from 'moment-timezone'; // import moment from 'moment-timezone';
import { storage as storageConfig } from '../../../config/vars'; import { storage as storageConfig } from '../../../config/vars';
@ -122,3 +123,119 @@ module.exports = {
uploader, uploader,
fileFilter fileFilter
}; };
=======
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();
// const year = moment(date).format('YYYY');
// const month = moment(date).format('MM');
const filePath = `${storageConfig.uri}`;
const createDefaultFolder = ({ id }) => {
try {
if (id) {
multer({ dest: `${filePath}/${id}` });
} else {
multer({ dest: `${filePath}` });
}
// multer({ dest: `${filePath}/images/games` });
// multer({ dest: `${filePath}/images/stories` });
// multer({ dest: `${filePath}/images/chapters` });
// multer({ dest: `${filePath}/images/vouchers` });
// multer({ dest: `${filePath}/images/products` });
// multer({ dest: `${filePath}/images/customers` });
// multer({ dest: `${filePath}/images/promotions` });
// // configuration
// multer({ dest: `${filePath}/images/banners` });
// multer({ dest: `${filePath}/images/categories` });
// multer({ dest: `${filePath}/images/upload/default` });
return true;
} catch (ex) {
return false;
}
};
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` });
// multer({ dest: `${filePath}/images/vouchers` });
// multer({ dest: `${filePath}/images/products` });
// multer({ dest: `${filePath}/images/customers` });
// multer({ dest: `${filePath}/images/promotions` });
// // configuration
// 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;
}
};
/** add image to storage follow group */
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, filePath);
},
filename: (req, file, cb) => {
/**
* setup folder follow date
*/
createDefaultFolder({});
console.log('run in herer', req.query.path, file);
/**
* save image follow type
*/
const path = req.query.path;
// const fileName = file.originalname.includes('.')
// ? file.originalname.slice(0, file.originalname.lastIndexOf('.'))
// : file.originalname;
cb(
null,
`/${path}/${file.originalname.replace(/\s/g, '')}`
);
}
});
const fileFilter = (req, file, cb) => {
// if (
// file.mimetype === 'image/jpeg' ||
// file.mimetype === 'image/webp' ||
// file.mimetype === 'image/png' ||
// file.mimetype === 'image/gif' ||
// ) {
// cb(null, true);
// } else {
// cb(null, false);
// }
cb(null, true);
};
const uploader = multer({
storage,
limits: {
fileSize: 1024 * 1024 * 5048 // 5MB
},
fileFilter
});
module.exports = {
createDefaultFolder,
createFolder,
uploader,
fileFilter
};
>>>>>>> 7bd4b58a0df174b4a8c26c34b9d388fc8ab3c4fd

Loading…
Cancel
Save