Added short url on upload
This commit is contained in:
parent
90adfe0b23
commit
95481a07fa
8 changed files with 99 additions and 4 deletions
72
package-lock.json
generated
72
package-lock.json
generated
|
@ -9,6 +9,7 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "CC-BY-NC-SA-4.0",
|
"license": "CC-BY-NC-SA-4.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^1.6.2",
|
||||||
"connect-ensure-login": "^0.1.1",
|
"connect-ensure-login": "^0.1.1",
|
||||||
"connect-flash": "^0.1.1",
|
"connect-flash": "^0.1.1",
|
||||||
"connect-mongo": "^5.0.0",
|
"connect-mongo": "^5.0.0",
|
||||||
|
@ -2255,6 +2256,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz",
|
||||||
"integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ=="
|
"integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/asynckit": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
|
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||||
|
},
|
||||||
"node_modules/autoprefixer": {
|
"node_modules/autoprefixer": {
|
||||||
"version": "9.8.8",
|
"version": "9.8.8",
|
||||||
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.8.8.tgz",
|
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.8.8.tgz",
|
||||||
|
@ -2292,6 +2298,16 @@
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/axios": {
|
||||||
|
"version": "1.6.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz",
|
||||||
|
"integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==",
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.15.0",
|
||||||
|
"form-data": "^4.0.0",
|
||||||
|
"proxy-from-env": "^1.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/b4a": {
|
"node_modules/b4a": {
|
||||||
"version": "1.6.4",
|
"version": "1.6.4",
|
||||||
"resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz",
|
"resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz",
|
||||||
|
@ -2734,6 +2750,17 @@
|
||||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
||||||
},
|
},
|
||||||
|
"node_modules/combined-stream": {
|
||||||
|
"version": "1.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
|
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||||
|
"dependencies": {
|
||||||
|
"delayed-stream": "~1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/commander": {
|
"node_modules/commander": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
|
||||||
|
@ -3161,6 +3188,14 @@
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/delayed-stream": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/depd": {
|
"node_modules/depd": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
||||||
|
@ -4023,6 +4058,25 @@
|
||||||
"integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==",
|
"integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/follow-redirects": {
|
||||||
|
"version": "1.15.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz",
|
||||||
|
"integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "individual",
|
||||||
|
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"debug": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/for-each": {
|
"node_modules/for-each": {
|
||||||
"version": "0.3.3",
|
"version": "0.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz",
|
||||||
|
@ -4031,6 +4085,19 @@
|
||||||
"is-callable": "^1.1.3"
|
"is-callable": "^1.1.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/form-data": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||||
|
"dependencies": {
|
||||||
|
"asynckit": "^0.4.0",
|
||||||
|
"combined-stream": "^1.0.8",
|
||||||
|
"mime-types": "^2.1.12"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/forwarded": {
|
"node_modules/forwarded": {
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||||
|
@ -6497,6 +6564,11 @@
|
||||||
"node": ">= 0.10"
|
"node": ">= 0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/proxy-from-env": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||||
|
},
|
||||||
"node_modules/pstree.remy": {
|
"node_modules/pstree.remy": {
|
||||||
"version": "1.1.8",
|
"version": "1.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
|
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
"sass": "^1.68.0"
|
"sass": "^1.68.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^1.6.2",
|
||||||
"connect-ensure-login": "^0.1.1",
|
"connect-ensure-login": "^0.1.1",
|
||||||
"connect-flash": "^0.1.1",
|
"connect-flash": "^0.1.1",
|
||||||
"connect-mongo": "^5.0.0",
|
"connect-mongo": "^5.0.0",
|
||||||
|
|
|
@ -6,6 +6,7 @@ import mongoose from 'mongoose';
|
||||||
import flash from 'connect-flash';
|
import flash from 'connect-flash';
|
||||||
import session from 'express-session';
|
import session from 'express-session';
|
||||||
import MongoStore from 'connect-mongo';
|
import MongoStore from 'connect-mongo';
|
||||||
|
import {DateTime} from 'luxon';
|
||||||
|
|
||||||
import passportConfig from './libs/passport';
|
import passportConfig from './libs/passport';
|
||||||
|
|
||||||
|
@ -115,6 +116,7 @@ app.use((error, req, res, next) => {
|
||||||
query: {},
|
query: {},
|
||||||
user: req.user,
|
user: req.user,
|
||||||
error,
|
error,
|
||||||
|
DateTime,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,4 +5,6 @@ module.exports = {
|
||||||
mongoDbUri: process.env.MONGODB_URI || 'mongodb://images-upload-db/upload',
|
mongoDbUri: process.env.MONGODB_URI || 'mongodb://images-upload-db/upload',
|
||||||
secret: process.env.SECRET || 'waemaeMe5ahc6ce1chaeKohKa6Io8Eik',
|
secret: process.env.SECRET || 'waemaeMe5ahc6ce1chaeKohKa6Io8Eik',
|
||||||
pagination: Number(process.env.PAGINATION || 16),
|
pagination: Number(process.env.PAGINATION || 16),
|
||||||
|
shortUrlUri: process.env.SHORT_URL_URI || 'https://short.darkou.link/yourls-api.php',
|
||||||
|
shortUrlSig: process.env.SHORT_URL_SIG,
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,12 +3,13 @@ import {join, extname} from 'path';
|
||||||
import multer from 'multer';
|
import multer from 'multer';
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
import {uid} from 'rand-token';
|
import {uid} from 'rand-token';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
import Pages from './Pages';
|
import Pages from './Pages';
|
||||||
|
|
||||||
import {getBaseUrl} from '../helpers';
|
import {getBaseUrl} from '../helpers';
|
||||||
|
|
||||||
import {pagination} from '../config';
|
import {pagination, shortUrlSig, shortUrlUri} from '../config';
|
||||||
|
|
||||||
const checkAndCreateDirectory = async (directory) => {
|
const checkAndCreateDirectory = async (directory) => {
|
||||||
try {
|
try {
|
||||||
|
@ -123,10 +124,15 @@ class Uploads extends Pages {
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const originalFile = `${userUri}/${originalFileName}`;
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
const urlshort = await axios.get(`${shortUrlUri}?signature=${shortUrlSig}&action=shorturl&url=${originalFile}&format=json`);
|
||||||
|
|
||||||
this.pageContent.page.upload = {
|
this.pageContent.page.upload = {
|
||||||
originalFile: `${userUri}/${originalFileName}`,
|
originalFile,
|
||||||
mediumFile: `${userUri}/${mediumFileName}`,
|
mediumFile: `${userUri}/${mediumFileName}`,
|
||||||
smallFile: `${userUri}/${smallFileName}`,
|
smallFile: `${userUri}/${smallFileName}`,
|
||||||
|
urlshort: urlshort.data.shorturl,
|
||||||
};
|
};
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
<img src="/img/logo.png" id="previewImage" alt="Image">
|
<img src="/img/logo.png" id="previewImage" alt="Image">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<%- include('../partials/details', {file: {}, index: 0}) %>
|
<%- include('../partials/details', {file: {}, index: 0, hideShortUrl: true}) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<img src="<%= page.upload.smallFile %>" alt="Miniature">
|
<img src="<%= page.upload.smallFile %>" alt="Miniature">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<%- include('../partials/details', {file: page.upload, index: 0}) %>
|
<%- include('../partials/details', {file: page.upload, index: 0, hideShortUrl: false}) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
@ -8,6 +8,18 @@
|
||||||
onclick="copyToClipboard('originalFile-<%= index %>', 'Lien copié')"
|
onclick="copyToClipboard('originalFile-<%= index %>', 'Lien copié')"
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
<% if ( hideShortUrl === false ) { %>
|
||||||
|
<div class="field">
|
||||||
|
<label for="urlshort-<%= index %>">Taille originale (url raccourcie)</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="urlshort-<%= index %>"
|
||||||
|
id="urlshort-<%= index %>"
|
||||||
|
value="<%= file.urlshort %>"
|
||||||
|
onclick="copyToClipboard('urlshort-<%= index %>', 'Lien copié')"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="mediumFile-<%= index %>">Taille moyenne (800x600)</label>
|
<label for="mediumFile-<%= index %>">Taille moyenne (800x600)</label>
|
||||||
<input
|
<input
|
||||||
|
|
Loading…
Reference in a new issue