mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
Convert require to import packages
This commit is contained in:
parent
ba8ebca21c
commit
07847e06c5
9
package-lock.json
generated
9
package-lock.json
generated
@ -3260,6 +3260,15 @@
|
||||
"integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/archiver": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/archiver/-/archiver-5.1.0.tgz",
|
||||
"integrity": "sha512-baFOhanb/hxmcOd1Uey2TfFg43kTSmM6py1Eo7Rjbv/ivcl7PXLhY0QgXGf50Hx/eskGCFqPfhs/7IZLb15C5g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/glob": "*"
|
||||
}
|
||||
},
|
||||
"@types/bcrypt": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/bcrypt/-/bcrypt-3.0.1.tgz",
|
||||
|
@ -76,6 +76,7 @@
|
||||
"@angular/platform-browser-dynamic": "11.2.9",
|
||||
"@angular/router": "11.2.9",
|
||||
"@ngx-loading-bar/core": "5.1.1",
|
||||
"@types/archiver": "^5.1.0",
|
||||
"@types/bcrypt": "3.0.1",
|
||||
"@types/bcryptjs": "2.4.2",
|
||||
"@types/chai": "4.2.16",
|
||||
|
@ -1,5 +1,6 @@
|
||||
import * as path from 'path';
|
||||
import {promises as fsp} from 'fs';
|
||||
import * as archiver from 'archiver';
|
||||
import {NextFunction, Request, Response} from 'express';
|
||||
import {ErrorCodes, ErrorDTO} from '../../common/entities/Error';
|
||||
import {DirectoryDTO, DirectoryDTOUtils} from '../../common/entities/DirectoryDTO';
|
||||
@ -75,8 +76,6 @@ export class GalleryMWs {
|
||||
res.set('Content-Type', 'application/zip');
|
||||
res.set('Content-Disposition', 'attachment; filename=Gallery.zip');
|
||||
|
||||
const fs = require('fs');
|
||||
const archiver = require('archiver');
|
||||
const archive = archiver('zip');
|
||||
|
||||
res.on('close', function() {
|
||||
@ -89,21 +88,18 @@ export class GalleryMWs {
|
||||
|
||||
archive.pipe(res);
|
||||
|
||||
// append photos in selected directory
|
||||
// append photos in absoluteDirectoryName
|
||||
// using case-insensitive glob of extensions
|
||||
for (const ext of SupportedFormats.WithDots.Photos) {
|
||||
archive.glob(`*${ext}`, {cwd:absoluteDirectoryName, nocase:true});
|
||||
}
|
||||
// append videos in selected directory
|
||||
// append videos in absoluteDirectoryName
|
||||
// using case-insensitive glob of extensions
|
||||
for (const ext of SupportedFormats.WithDots.Videos) {
|
||||
archive.glob(`*${ext}`, {cwd:absoluteDirectoryName, nocase:true});
|
||||
}
|
||||
|
||||
await archive.finalize(function(err: any) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
req.resultPipe = true;
|
||||
});
|
||||
await archive.finalize();
|
||||
return next();
|
||||
|
||||
} catch (err) {
|
||||
|
@ -71,13 +71,6 @@ export class RenderingMWs {
|
||||
return res.sendFile(req.resultPipe, {maxAge: 31536000, dotfiles: 'allow'});
|
||||
}
|
||||
|
||||
public static renderZipStream(req: Request, res: Response, next: NextFunction): any {
|
||||
if (!req.resultPipe) {
|
||||
return next();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static renderOK(req: Request, res: Response, next: NextFunction): void {
|
||||
const message = new Message<string>(null, 'ok');
|
||||
res.json(message);
|
||||
|
@ -53,8 +53,7 @@ export class GalleryRouter {
|
||||
AuthenticationMWs.authorisePath('directory', true),
|
||||
|
||||
// specific part
|
||||
GalleryMWs.zipDirectory,
|
||||
RenderingMWs.renderZipStream
|
||||
GalleryMWs.zipDirectory
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user