Merge branch 'develop'

This commit is contained in:
Alice Gaudon 2020-07-09 14:22:55 +02:00
commit a3b6e44306
5 changed files with 88 additions and 55 deletions

View File

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

View File

@ -9,6 +9,7 @@ import AuthToken from "../models/AuthToken";
import {IncomingForm} from "formidable";
import {FILE_UPLOAD_MIDDLEWARE} from "wms-core/components/ExpressAppComponent";
import generateSlug from "../SlugGenerator";
import Logger from "wms-core/Logger";
export default class FileController extends Controller {
@ -17,7 +18,7 @@ export default class FileController extends Controller {
this.get('/files/upload/script', this.downloadLinuxScript, 'file-linux-script');
this.post('/files/post', this.postFileFrontend, 'post-file-frontend', REQUIRE_AUTH_MIDDLEWARE, FILE_UPLOAD_FORM_MIDDLEWARE);
this.get('/files/:page([0-9]+)?', this.getFileManager, 'file-manager', REQUIRE_AUTH_MIDDLEWARE);
this.post('/files/delete/:slug', FileController.deleteFile, 'delete-file-frontend', REQUIRE_AUTH_MIDDLEWARE);
this.post('/files/delete/:slug', FileController.deleteFileRoute, 'delete-file-frontend', REQUIRE_AUTH_MIDDLEWARE);
}
protected async getFileUploader(req: Request, res: Response): Promise<void> {
@ -86,7 +87,7 @@ export default class FileController extends Controller {
});
}
public static async deleteFile(req: Request, res: Response, next: NextFunction): Promise<void> {
public static async deleteFileRoute(req: Request, res: Response, next: NextFunction): Promise<void> {
const slug = req.params.slug;
if (!slug) throw new BadRequestError('Cannot delete nothing.', 'Please provide a slug.', req.url);
@ -96,8 +97,7 @@ export default class FileController extends Controller {
switch (file.storage_type) {
case 'local':
await file.delete();
fs.unlinkSync(file.storage_path);
await this.deleteFile(file);
break;
default:
throw new ServerError(`This file cannot be deleted. Deletion protocol for ${file.storage_type} storage type not implemented.`);
@ -114,6 +114,12 @@ export default class FileController extends Controller {
},
});
}
public static async deleteFile(file: FileModel): Promise<void> {
fs.unlinkSync(file.storage_path);
await file.delete();
Logger.info('Deleted', file.storage_path, `(${file.real_name})`);
}
}

View File

@ -6,15 +6,13 @@ import {REQUIRE_REQUEST_AUTH_MIDDLEWARE} from "wms-core/auth/AuthComponent";
import URLRedirect from "../models/URLRedirect";
import URLRedirectController from "./URLRedirectController";
import FileModel from "../models/FileModel";
import fs from "fs";
import Logger from "wms-core/Logger";
import generateSlug from "../SlugGenerator";
import FileController, {FILE_UPLOAD_FORM_MIDDLEWARE} from "./FileController";
export default class LinkController extends Controller {
routes(): void {
this.post('/', this.postFile, 'post-file', REQUIRE_REQUEST_AUTH_MIDDLEWARE, FILE_UPLOAD_FORM_MIDDLEWARE);
this.delete('/:slug', FileController.deleteFile, 'delete-file', REQUIRE_REQUEST_AUTH_MIDDLEWARE);
this.delete('/:slug', FileController.deleteFileRoute, 'delete-file', REQUIRE_REQUEST_AUTH_MIDDLEWARE);
this.get('/:slug', this.downloadFile, 'get-file');
this.put('/:slug', this.putFile, 'put-file', REQUIRE_REQUEST_AUTH_MIDDLEWARE, FILE_UPLOAD_FORM_MIDDLEWARE);
@ -27,12 +25,11 @@ export default class LinkController extends Controller {
}
protected async downloadFile(req: Request, res: Response, next: NextFunction): Promise<void> {
console.log('get file', req.params.slug)
const file = await FileModel.getBySlug(req.params.slug);
if (!file) return next();
if (file.shouldBeDeleted()) {
await fs.unlinkSync(file.storage_path);
await file.delete();
Logger.info('Deleted', file.storage_path, `(${file.real_name})`);
await FileController.deleteFile(file);
return next();
}

View File

@ -39,9 +39,13 @@
{% set expires_at = file.getExpirationDate() %}
<td>{% if expires_at %}{{ expires_at.toISOString() }}{% else %}Never{% endif %}</td>
<td>
{% if file.shouldBeDeleted() %}
Pending deletion
{% else %}
<form action="{{ route('delete-file-frontend', file.slug) }}" method="post">
<button class="button danger"><i data-feather="trash"></i> Delete</button>
</form>
{% endif %}
</td>
</tr>
{% endfor %}

108
yarn.lock
View File

@ -1094,9 +1094,9 @@
"@babel/types" "^7.0.0"
"@types/babel__traverse@*", "@types/babel__traverse@^7.0.6":
version "7.0.12"
resolved "https://registry.toot.party/@types%2fbabel__traverse/-/babel__traverse-7.0.12.tgz#22f49a028e69465390f87bb103ebd61bd086b8f5"
integrity sha512-t4CoEokHTfcyfb4hUaF9oOHu9RmmNWnm1CP0YmMqOOfClKascOmvlEM736vlqeScuGvBDsHkf8R2INd4DWreQA==
version "7.0.13"
resolved "https://registry.toot.party/@types%2fbabel__traverse/-/babel__traverse-7.0.13.tgz#1874914be974a492e1b4cb00585cabb274e8ba18"
integrity sha512-i+zS7t6/s9cdQvbqKDARrcbrPvtJGlbYsMkazo03nTAK3RX9FNrLllXys22uiTGJapPOTZTQ35nHh4ISph4SLQ==
dependencies:
"@babel/types" "^7.3.0"
@ -1148,9 +1148,9 @@
"@types/node" "*"
"@types/express@*", "@types/express@^4.17.6":
version "4.17.6"
resolved "https://registry.toot.party/@types%2fexpress/-/express-4.17.6.tgz#6bce49e49570507b86ea1b07b806f04697fac45e"
integrity sha512-n/mr9tZI83kd4azlPG5y997C/M4DNABK9yErhFM6hKdym4kkmd9j0vtsJyjFIwfRBxtrxZtAfGZCNRIBMFLK5w==
version "4.17.7"
resolved "https://registry.toot.party/@types%2fexpress/-/express-4.17.7.tgz#42045be6475636d9801369cd4418ef65cdb0dd59"
integrity sha512-dCOT5lcmV/uC2J9k0rPafATeeyz+99xTt54ReX11/LObZgfzJqZNcW27zGhYyX+9iSEGXGt5qLPwRSvBZcLvtQ==
dependencies:
"@types/body-parser" "*"
"@types/express-serve-static-core" "*"
@ -1166,9 +1166,9 @@
"@types/node" "*"
"@types/glob@^7.1.1":
version "7.1.2"
resolved "https://registry.toot.party/@types%2fglob/-/glob-7.1.2.tgz#06ca26521353a545d94a0adc74f38a59d232c987"
integrity sha512-VgNIkxK+j7Nz5P7jvUZlRvhuPSmsEfS03b0alKcq5V/STUKAa3Plemsn5mrQUO7am6OErJ4rhGEGJbACclrtRA==
version "7.1.3"
resolved "https://registry.toot.party/@types%2fglob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183"
integrity sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==
dependencies:
"@types/minimatch" "*"
"@types/node" "*"
@ -1231,14 +1231,14 @@
"@types/node" "*"
"@types/node@*":
version "14.0.14"
resolved "https://registry.toot.party/@types%2fnode/-/node-14.0.14.tgz#24a0b5959f16ac141aeb0c5b3cd7a15b7c64cbce"
integrity sha512-syUgf67ZQpaJj01/tRTknkMNoBBLWJOBODF0Zm4NrXmiSuxjymFrxnTu1QVYRubhVkRcZLYZG8STTwJRdVm/WQ==
version "14.0.20"
resolved "https://registry.toot.party/@types%2fnode/-/node-14.0.20.tgz#0da05cddbc761e1fa98af88a17244c8c1ff37231"
integrity sha512-MRn/NP3dee8yL5QhbSA6riuwkS+UOcsPUMOIOG3KMUQpuor/2TopdRBu8QaaB4fGU+gz/bzyDWt0FtUbeJ8H1A==
"@types/node@^13.13.2":
version "13.13.12"
resolved "https://registry.toot.party/@types%2fnode/-/node-13.13.12.tgz#9c72e865380a7dc99999ea0ef20fc9635b503d20"
integrity sha512-zWz/8NEPxoXNT9YyF2osqyA9WjssZukYpgI4UYZpOjcyqwIUqWGkcCionaEb9Ki+FULyPyvNFpg/329Kd2/pbw==
version "13.13.13"
resolved "https://registry.toot.party/@types%2fnode/-/node-13.13.13.tgz#71217d90fd9c9c937e28628772d5c0b432c79355"
integrity sha512-UfvBE9oRCAJVzfR+3eWm/sdLFe/qroAPEXP3GPJ1SehQiEVgZT6NQZWYbPMiJ3UdcKM06v4j+S1lTcdWCmw+3g==
"@types/nodemailer@^6.4.0":
version "6.4.0"
@ -1486,7 +1486,7 @@ abbrev@1:
resolved "https://registry.toot.party/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==
accepts@~1.3.7:
accepts@~1.3.5, accepts@~1.3.7:
version "1.3.7"
resolved "https://registry.toot.party/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd"
integrity sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==
@ -1523,9 +1523,9 @@ ajv-errors@^1.0.0:
integrity sha512-DCRfO/4nQ+89p/RK43i8Ezd41EqdGIU4ld7nGF8OQ14oc/we5rEntLCUa7+jrn3nn83BosfwZA0wb4pon2o8iQ==
ajv-keywords@^3.1.0, ajv-keywords@^3.4.1:
version "3.5.0"
resolved "https://registry.toot.party/ajv-keywords/-/ajv-keywords-3.5.0.tgz#5c894537098785926d71e696114a53ce768ed773"
integrity sha512-eyoaac3btgU8eJlvh01En8OCKzRqlLe2G5jDsCr3RiE2uLGMEEB1aaGwVVpwR8M95956tGH6R+9edC++OvzaVw==
version "3.5.1"
resolved "https://registry.toot.party/ajv-keywords/-/ajv-keywords-3.5.1.tgz#b83ca89c5d42d69031f424cad49aada0236c6957"
integrity sha512-KWcq3xN8fDjSB+IMoh2VaXVhRI0BBGxoYp3rx7Pkb6z0cFjYR9Q9l4yZqqals0/zsioCmocC5H6UvsGD4MoIBA==
ajv@^6.1.0, ajv@^6.10.2, ajv@^6.12.2, ajv@^6.5.5:
version "6.12.3"
@ -2227,6 +2227,11 @@ builtin-status-codes@^3.0.0:
resolved "https://registry.toot.party/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8"
integrity sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=
bytes@3.0.0:
version "3.0.0"
resolved "https://registry.toot.party/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
integrity sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=
bytes@3.1.0:
version "3.1.0"
resolved "https://registry.toot.party/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
@ -2326,9 +2331,9 @@ camelcase@^5.0.0, camelcase@^5.3.1:
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
caniuse-lite@^1.0.30001093:
version "1.0.30001094"
resolved "https://registry.toot.party/caniuse-lite/-/caniuse-lite-1.0.30001094.tgz#0b11d02e1cdc201348dbd8e3e57bd9b6ce82b175"
integrity sha512-ufHZNtMaDEuRBpTbqD93tIQnngmJ+oBknjvr0IbFympSdtFpAUFmNv4mVKbb53qltxFx0nK3iy32S9AqkLzUNA==
version "1.0.30001096"
resolved "https://registry.toot.party/caniuse-lite/-/caniuse-lite-1.0.30001096.tgz#5a4541af5317dc21f91f5b24d453030a35f919c0"
integrity sha512-PFTw9UyVfbkcMEFs82q8XVlRayj7HKvnhu5BLcmjGpv+SNyiWasCcWXPGJuO0rK0dhLRDJmtZcJ+LHUfypbw1w==
capture-exit@^2.0.0:
version "2.0.0"
@ -2627,6 +2632,26 @@ component-emitter@^1.2.1:
resolved "https://registry.toot.party/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"
integrity sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==
compressible@~2.0.16:
version "2.0.18"
resolved "https://registry.toot.party/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba"
integrity sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==
dependencies:
mime-db ">= 1.43.0 < 2"
compression@^1.7.4:
version "1.7.4"
resolved "https://registry.toot.party/compression/-/compression-1.7.4.tgz#95523eff170ca57c29a0ca41e6fe131f41e5bb8f"
integrity sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==
dependencies:
accepts "~1.3.5"
bytes "3.0.0"
compressible "~2.0.16"
debug "2.6.9"
on-headers "~1.0.2"
safe-buffer "5.1.2"
vary "~1.1.2"
concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.toot.party/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@ -3415,9 +3440,9 @@ ee-first@1.1.1:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
electron-to-chromium@^1.3.488:
version "1.3.488"
resolved "https://registry.toot.party/electron-to-chromium/-/electron-to-chromium-1.3.488.tgz#9226229f5fbc825959210e81e0bb3e63035d1c06"
integrity sha512-NReBdOugu1yl8ly+0VDtiQ6Yw/1sLjnvflWq0gvY1nfUXU2PbA+1XAVuEb7ModnwL/MfUPjby7e4pAFnSHiy6Q==
version "1.3.494"
resolved "https://registry.toot.party/electron-to-chromium/-/electron-to-chromium-1.3.494.tgz#0d2dba65b69d696c5b71abb37552ff055fb32a5c"
integrity sha512-EOZuaDT3L1sCIMAVN5J0nGuGWVq5dThrdl0d8XeDYf4MOzbXqZ19OLKesN8TZj0RxtpYjqHpiw/fR6BKWdMwYA==
elliptic@^6.0.0, elliptic@^6.5.2:
version "6.5.3"
@ -3659,9 +3684,9 @@ execa@^3.2.0:
strip-final-newline "^2.0.0"
execa@^4.0.0:
version "4.0.2"
resolved "https://registry.toot.party/execa/-/execa-4.0.2.tgz#ad87fb7b2d9d564f70d2b62d511bee41d5cbb240"
integrity sha512-QI2zLa6CjGWdiQsmSkZoGtDx2N+cQIGb3yNolGTdjSQzydzLgYYf8LRuagp7S7fPimjcrzUDSUFd/MgzELMi4Q==
version "4.0.3"
resolved "https://registry.toot.party/execa/-/execa-4.0.3.tgz#0a34dabbad6d66100bd6f2c576c8669403f317f2"
integrity sha512-WFDXGHckXPWZX19t1kCsXzOpqX9LWYNqn4C+HqZlk/V0imTkzJZqf87ZBhvpHaftERYknpk0fjSylnXVlVgI0A==
dependencies:
cross-spawn "^7.0.0"
get-stream "^5.0.0"
@ -5628,9 +5653,9 @@ jest@^25.4.0:
jest-cli "^25.5.4"
js-base64@^2.1.8:
version "2.6.2"
resolved "https://registry.toot.party/js-base64/-/js-base64-2.6.2.tgz#cf9301bc5cc756892a9a6c8d7138322e5944fb0d"
integrity sha512-1hgLrLIrmCgZG+ID3VoLNLOSwjGnoZa8tyrUdEteMeIzsT6PH7PMLyUvbDwzNE56P3PNxyvuIOx4Uh2E5rzQIw==
version "2.6.3"
resolved "https://registry.toot.party/js-base64/-/js-base64-2.6.3.tgz#7afdb9b57aa7717e15d370b66e8f36a9cb835dc3"
integrity sha512-fiUvdfCaAXoQTHdKMgTvg6IkecXDcVz6V5rlftUTclF9IKBjMizvSdQaCl/z/6TApDeby5NL+axYou3i0mu1Pg==
js-beautify@^1.6.14:
version "1.11.0"
@ -5980,9 +6005,9 @@ lodash.unescape@^4.0.1:
integrity sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=
lodash@^4.0.0, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@~4.17.10:
version "4.17.15"
resolved "https://registry.toot.party/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
version "4.17.19"
resolved "https://registry.toot.party/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==
logalot@^2.0.0, logalot@^2.1.0:
version "2.1.0"
@ -6231,7 +6256,7 @@ miller-rabin@^4.0.0:
bn.js "^4.0.0"
brorand "^1.0.1"
mime-db@1.44.0, mime-db@^1.28.0:
mime-db@1.44.0, "mime-db@>= 1.43.0 < 2", mime-db@^1.28.0:
version "1.44.0"
resolved "https://registry.toot.party/mime-db/-/mime-db-1.44.0.tgz#fa11c5eb0aca1334b4233cb4d52f10c5a6272f92"
integrity sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==
@ -6894,9 +6919,9 @@ node-pre-gyp@^0.14.0:
tar "^4.4.2"
node-releases@^1.1.58:
version "1.1.58"
resolved "https://registry.toot.party/node-releases/-/node-releases-1.1.58.tgz#8ee20eef30fa60e52755fcc0942def5a734fe935"
integrity sha512-NxBudgVKiRh/2aPWMgPR7bPTX0VPmGx5QBwCtdHitnqFE5/O8DeBXuIMH1nwNnw/aMo6AjOrpsHzfY3UbUJ7yg==
version "1.1.59"
resolved "https://registry.toot.party/node-releases/-/node-releases-1.1.59.tgz#4d648330641cec704bff10f8e4fe28e453ab8e8e"
integrity sha512-H3JrdUczbdiwxN5FuJPyCHnGHIFqQ0wWxo+9j1kAXAzqNMAHlo+4I/sYYxpyK0irQ73HgdiyzD32oqQDcU2Osw==
node-sass@^4.14.0:
version "4.14.1"
@ -9839,9 +9864,9 @@ widest-line@^3.1.0:
string-width "^4.0.0"
wms-core@^0:
version "0.10.19"
resolved "https://registry.toot.party/wms-core/-/wms-core-0.10.19.tgz#d04830bd66ea5ee2e43b7314dfa8c92e6b11697f"
integrity sha512-9DGTKtdKho8FJV5b0k7D6/21zFjOQTbJz4wkvTdgW+EL2iriH9ojFVRaakGqgb3WoxejZFaz14HSYysNAJ4Xsw==
version "0.11.0"
resolved "https://registry.toot.party/wms-core/-/wms-core-0.11.0.tgz#fb7216024561ebcaa841e3b2abb2f40e8cb97dcb"
integrity sha512-+oldFhwConda/KbtIV9Pk+VkoZbcoyc66LRVhQfI9tTDw3Jt8+pbyqO/ctg2u17yp21r/q00zLrSqbV45YtGIg==
dependencies:
"@types/express" "^4.17.6"
"@types/express-session" "^1.17.0"
@ -9851,6 +9876,7 @@ wms-core@^0:
"@types/redis" "^2.8.18"
"@types/ws" "^7.2.4"
argon2 "^0.26.2"
compression "^1.7.4"
config "^3.3.1"
connect-flash "^0.1.1"
connect-redis "^4.0.4"