Merge branch 'develop'

This commit is contained in:
Alice Gaudon 2020-11-22 12:40:12 +01:00
commit 4ad2e1bd59
2 changed files with 22 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "ily.li", "name": "ily.li",
"version": "0.5.2", "version": "0.5.3",
"description": "Self-hosted file pusher", "description": "Self-hosted file pusher",
"repository": "https://gitlab.com/ArisuOngaku/ily.li", "repository": "https://gitlab.com/ArisuOngaku/ily.li",
"author": "Alice Gaudon <alice@gaudon.pro>", "author": "Alice Gaudon <alice@gaudon.pro>",

View File

@ -1,6 +1,6 @@
import Controller from "wms-core/Controller"; import Controller from "wms-core/Controller";
import {NextFunction, Request, Response} from "express"; import {NextFunction, Request, Response} from "express";
import {BadRequestError, ForbiddenHttpError, NotFoundHttpError, ServerError} from "wms-core/HttpError"; import {BadRequestError, NotFoundHttpError, ServerError} from "wms-core/HttpError";
import config from "config"; import config from "config";
import {REQUIRE_REQUEST_AUTH_MIDDLEWARE} from "wms-core/auth/AuthComponent"; import {REQUIRE_REQUEST_AUTH_MIDDLEWARE} from "wms-core/auth/AuthComponent";
import URLRedirect from "../models/URLRedirect"; import URLRedirect from "../models/URLRedirect";
@ -10,6 +10,9 @@ import generateSlug from "../SlugGenerator";
import FileController, {FILE_UPLOAD_FORM_MIDDLEWARE} from "./FileController"; import FileController, {FILE_UPLOAD_FORM_MIDDLEWARE} from "./FileController";
import * as fs from "fs"; import * as fs from "fs";
import {encodeRFC5987ValueChars} from "../Utils"; import {encodeRFC5987ValueChars} from "../Utils";
import {promisify} from "util";
import * as buffer from "buffer";
import Logger from "wms-core/Logger";
export default class LinkController extends Controller { export default class LinkController extends Controller {
routes(): void { routes(): void {
@ -35,6 +38,16 @@ export default class LinkController extends Controller {
return next(); return next();
} }
switch (file.storage_type) {
case 'local':
const stats = await promisify(fs.stat)(file.storage_path!);
// If file is bigger than max supported one shot reading, fallback to express download
if (stats.size > buffer.constants.MAX_LENGTH) {
Logger.info(`Fallback to express download for file of size ${stats.size}`);
return res.download(file.storage_path!);
}
// File type // File type
const fileName = file.real_name!; const fileName = file.real_name!;
const parts = fileName.split('.'); const parts = fileName.split('.');
@ -43,8 +56,6 @@ export default class LinkController extends Controller {
// File name // File name
res.header('Content-Disposition', `inline; filename*=UTF-8''${encodeRFC5987ValueChars(fileName)}`); res.header('Content-Disposition', `inline; filename*=UTF-8''${encodeRFC5987ValueChars(fileName)}`);
switch (file.storage_type) {
case 'local':
fs.readFile(file.storage_path!, (err, data) => { fs.readFile(file.storage_path!, (err, data) => {
if (err) return next(err); if (err) return next(err);
res.send(data); res.send(data);