浏览代码

Async who?

Pitu 7 年之前
父节点
当前提交
76d48602c6
共有 1 个文件被更改,包括 6 次插入7 次删除
  1. 6 7
      controllers/albumsController.js

+ 6 - 7
controllers/albumsController.js

@@ -152,13 +152,12 @@ albumsController.generateZip = async (req, res, next) => {
 		let archive = new Zip();
 
 		for (let file of files) {
-			fs.stat(path.join(__dirname, '..', config.uploads.folder, file.name), (err, stats) => {
-				if (err) {
-					console.log(err);
-				} else {
-					archive.file(file.name, fs.readFileSync(path.join(__dirname, '..', config.uploads.folder, file.name)));
-				}
-			});
+			try {
+				const exists = fs.statSync(path.join(__dirname, '..', config.uploads.folder, file.name));
+				archive.file(file.name, fs.readFileSync(path.join(__dirname, '..', config.uploads.folder, file.name)));
+			} catch (err) {
+				console.log(err);
+			}
 		}
 
 		archive