mirror of https://github.com/status-im/codimd.git
Merge pull request #1484 from hackmdio:feat/optimize-module-size
Feat/optimize module size
This commit is contained in:
commit
4a748cb53f
|
@ -2,7 +2,7 @@
|
|||
const config = require('../config')
|
||||
const logger = require('../logger')
|
||||
|
||||
const lutim = require('lib/imageRouter/lutim')
|
||||
const lutim = require('lutim')
|
||||
|
||||
exports.uploadImage = function (imagePath, callback) {
|
||||
if (!imagePath || typeof imagePath !== 'string') {
|
||||
|
|
|
@ -6,9 +6,10 @@ const config = require('../config')
|
|||
const { getImageMimeType } = require('../utils')
|
||||
const logger = require('../logger')
|
||||
|
||||
const AWS = require('aws-sdk')
|
||||
const awsConfig = new AWS.Config(config.s3)
|
||||
const s3 = new AWS.S3(awsConfig)
|
||||
const { S3Client } = require('@aws-sdk/client-s3-node/S3Client')
|
||||
const { PutObjectCommand } = require('@aws-sdk/client-s3-node/commands/PutObjectCommand')
|
||||
|
||||
const s3 = new S3Client(config.s3)
|
||||
|
||||
exports.uploadImage = function (imagePath, callback) {
|
||||
if (!imagePath || typeof imagePath !== 'string') {
|
||||
|
@ -32,16 +33,12 @@ exports.uploadImage = function (imagePath, callback) {
|
|||
Body: buffer,
|
||||
ACL: 'public-read'
|
||||
}
|
||||
|
||||
const mimeType = getImageMimeType(imagePath)
|
||||
if (mimeType) { params.ContentType = mimeType }
|
||||
|
||||
s3.putObject(params, function (err, data) {
|
||||
if (err) {
|
||||
callback(new Error(err), null)
|
||||
return
|
||||
}
|
||||
const command = new PutObjectCommand(params)
|
||||
|
||||
s3.send(command).then(data => {
|
||||
let s3Endpoint = 's3.amazonaws.com'
|
||||
if (config.s3.endpoint) {
|
||||
s3Endpoint = config.s3.endpoint
|
||||
|
@ -49,6 +46,10 @@ exports.uploadImage = function (imagePath, callback) {
|
|||
s3Endpoint = `s3-${config.s3.region}.amazonaws.com`
|
||||
}
|
||||
callback(null, `https://${s3Endpoint}/${config.s3bucket}/${params.Key}`)
|
||||
}).catch(err => {
|
||||
if (err) {
|
||||
callback(new Error(err), null)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
115
package.json
115
package.json
|
@ -30,25 +30,19 @@
|
|||
"postinstall": "bin/heroku"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hackmd/codemirror": "~5.49.5",
|
||||
"@aws-sdk/client-s3-node": "0.1.0-preview.2",
|
||||
"@hackmd/diff-match-patch": "~1.1.3",
|
||||
"@hackmd/idle-js": "~1.0.1",
|
||||
"@hackmd/imgur": "~0.5.0",
|
||||
"@hackmd/js-sequence-diagrams": "~0.0.1-alpha.3",
|
||||
"@hackmd/lz-string": "~1.4.4",
|
||||
"@hackmd/meta-marked": "~0.4.4",
|
||||
"@hackmd/pandoc.js": "^0.1.9",
|
||||
"@passport-next/passport-openid": "~1.0.0",
|
||||
"@susisu/mte-kernel": "^2.1.0",
|
||||
"archiver": "~3.1.1",
|
||||
"async": "~3.1.0",
|
||||
"aws-sdk": "~2.503.0",
|
||||
"azure-storage": "~2.10.3",
|
||||
"babel-polyfill": "~6.26.0",
|
||||
"base64url": "~3.0.1",
|
||||
"body-parser": "~1.19.0",
|
||||
"bootstrap": "~3.4.0",
|
||||
"bootstrap-validator": "~0.11.8",
|
||||
"chance": "~1.0.18",
|
||||
"cheerio": "~0.22.0",
|
||||
"connect-flash": "~0.1.1",
|
||||
|
@ -59,46 +53,17 @@
|
|||
"ejs": "~2.6.2",
|
||||
"express": "~4.17.1",
|
||||
"express-session": "~1.16.2",
|
||||
"file-saver": "~2.0.2",
|
||||
"flowchart.js": "~1.12.2",
|
||||
"fork-awesome": "~1.1.7",
|
||||
"formidable": "~1.2.1",
|
||||
"gist-embed": "~2.6.0",
|
||||
"graceful-fs": "~4.2.1",
|
||||
"handlebars": "~4.1.2",
|
||||
"helmet": "~3.20.0",
|
||||
"highlight.js": "~9.15.9",
|
||||
"https-proxy-agent": "^3.0.1",
|
||||
"i18n": "~0.8.3",
|
||||
"ionicons": "~2.0.1",
|
||||
"isomorphic-fetch": "~2.2.1",
|
||||
"jquery": "~3.4.1",
|
||||
"jquery-mousewheel": "~3.1.13",
|
||||
"jquery-ui": "~1.12.1",
|
||||
"js-cookie": "~2.2.0",
|
||||
"js-yaml": "~3.13.1",
|
||||
"jsdom-nogyp": "~0.8.3",
|
||||
"keymaster": "~1.6.2",
|
||||
"list.js": "~1.5.0",
|
||||
"lodash": "~4.17.15",
|
||||
"lutim": "~1.0.2",
|
||||
"markdown-it": "~10.0.0",
|
||||
"markdown-it-abbr": "~1.0.4",
|
||||
"markdown-it-container": "~2.0.0",
|
||||
"markdown-it-deflist": "~2.0.3",
|
||||
"markdown-it-footnote": "~3.0.2",
|
||||
"markdown-it-imsize": "~2.0.1",
|
||||
"markdown-it-ins": "~2.0.0",
|
||||
"markdown-it-mark": "~2.0.0",
|
||||
"markdown-it-mathjax": "~2.0.0",
|
||||
"markdown-it-regexp": "~0.4.0",
|
||||
"markdown-it-sub": "~1.0.0",
|
||||
"markdown-it-sup": "~1.0.0",
|
||||
"markdown-pdf": "~9.0.0",
|
||||
"markdownlint": "^0.17.0",
|
||||
"mathjax": "~2.7.5",
|
||||
"mattermost-redux": "~5.13.0",
|
||||
"mermaid": "~8.4.8",
|
||||
"method-override": "~3.0.0",
|
||||
"minimist": "~1.2.0",
|
||||
"minio": "^7.0.12",
|
||||
|
@ -119,50 +84,36 @@
|
|||
"passport-saml": "~1.0.0",
|
||||
"passport-twitter": "~1.0.4",
|
||||
"passport.socketio": "~3.7.0",
|
||||
"pdfobject": "~2.1.1",
|
||||
"pg": "~6.1.2",
|
||||
"pg-hstore": "~2.3.2",
|
||||
"plantuml-encoder": "^1.2.5",
|
||||
"prismjs": "~1.17.1",
|
||||
"randomcolor": "~0.5.4",
|
||||
"raphael": "~2.2.8",
|
||||
"readline-sync": "~1.4.7",
|
||||
"request": "~2.88.0",
|
||||
"reveal.js": "~3.9.2",
|
||||
"scrypt": "~6.0.3",
|
||||
"select2": "~3.5.2-browserify",
|
||||
"sequelize": "5.21.3",
|
||||
"sequelize-cli": "~5.5.1",
|
||||
"shortid": "~2.2.14",
|
||||
"socket.io": "~2.2.0",
|
||||
"socket.io-client": "~2.2.0",
|
||||
"spin.js": "~4.0.0",
|
||||
"sqlite3": "~4.0.9",
|
||||
"store": "~2.0.12",
|
||||
"tedious": "~6.2.0",
|
||||
"toobusy-js": "~0.5.1",
|
||||
"turndown": "~5.0.3",
|
||||
"uuid": "~3.3.2",
|
||||
"validator": "~11.1.0",
|
||||
"vega": "~5.9.1",
|
||||
"vega-embed": "~6.2.2",
|
||||
"vega-lite": "~4.4.0",
|
||||
"velocity-animate": "~1.5.2",
|
||||
"visibilityjs": "~2.0.2",
|
||||
"viz.js": "~2.1.2",
|
||||
"winston": "~3.2.1",
|
||||
"ws": "~7.1.1",
|
||||
"wurl": "~2.5.3",
|
||||
"xss": "~1.0.6"
|
||||
"ws": "~7.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@hackmd/codemirror": "~5.49.5",
|
||||
"@hackmd/emojify.js": "^2.1.0",
|
||||
"@hackmd/idle-js": "~1.0.1",
|
||||
"@hackmd/js-sequence-diagrams": "~0.0.1-alpha.3",
|
||||
"@susisu/mte-kernel": "^2.1.0",
|
||||
"acorn": "~6.1.1",
|
||||
"babel-core": "~6.26.3",
|
||||
"babel-loader": "~7.1.4",
|
||||
"babel-plugin-transform-runtime": "~6.23.0",
|
||||
"babel-preset-env": "~1.7.0",
|
||||
"babel-runtime": "~6.26.0",
|
||||
"bootstrap": "~3.4.0",
|
||||
"bootstrap-validator": "~0.11.8",
|
||||
"copy-webpack-plugin": "~4.5.2",
|
||||
"css-loader": "~1.0.0",
|
||||
"dictionary-de": "^2.0.3",
|
||||
|
@ -173,32 +124,80 @@
|
|||
"exports-loader": "~0.7.0",
|
||||
"expose-loader": "~0.7.5",
|
||||
"file-loader": "~2.0.0",
|
||||
"file-saver": "~2.0.2",
|
||||
"flowchart.js": "~1.12.2",
|
||||
"fork-awesome": "~1.1.7",
|
||||
"gist-embed": "~2.6.0",
|
||||
"graceful-fs": "~4.2.1",
|
||||
"handlebars": "~4.1.2",
|
||||
"highlight.js": "~9.15.9",
|
||||
"html-webpack-plugin": "~4.0.0-beta.2",
|
||||
"imports-loader": "~0.8.0",
|
||||
"intelli-espower-loader": "~1.0.1",
|
||||
"ionicons": "~2.0.1",
|
||||
"jquery": "~3.4.1",
|
||||
"jquery-mousewheel": "~3.1.13",
|
||||
"jquery-ui": "~1.12.1",
|
||||
"js-cookie": "~2.2.0",
|
||||
"js-yaml": "~3.13.1",
|
||||
"jsonlint": "~1.6.2",
|
||||
"keymaster": "~1.6.2",
|
||||
"leaflet": "~1.6.0",
|
||||
"less": "~3.9.0",
|
||||
"less-loader": "~4.1.0",
|
||||
"list.js": "~1.5.0",
|
||||
"markdown-it-abbr": "~1.0.4",
|
||||
"markdown-it-container": "~2.0.0",
|
||||
"markdown-it-deflist": "~2.0.3",
|
||||
"markdown-it-footnote": "~3.0.2",
|
||||
"markdown-it-imsize": "~2.0.1",
|
||||
"markdown-it-ins": "~2.0.0",
|
||||
"markdown-it-mark": "~2.0.0",
|
||||
"markdown-it-mathjax": "~2.0.0",
|
||||
"markdown-it-regexp": "~0.4.0",
|
||||
"markdown-it-ruby": "^0.1.1",
|
||||
"markdown-it-sub": "~1.0.0",
|
||||
"markdown-it-sup": "~1.0.0",
|
||||
"markdownlint": "^0.17.0",
|
||||
"mathjax": "~2.7.5",
|
||||
"mermaid": "~8.4.8",
|
||||
"mini-css-extract-plugin": "~0.4.1",
|
||||
"mocha": "~5.2.0",
|
||||
"mock-require": "~3.0.3",
|
||||
"nyc": "~14.0.0",
|
||||
"optimize-css-assets-webpack-plugin": "~5.0.0",
|
||||
"pdfobject": "~2.1.1",
|
||||
"plantuml-encoder": "^1.2.5",
|
||||
"power-assert": "~1.6.1",
|
||||
"prismjs": "^1.17.1",
|
||||
"raphael": "~2.2.8",
|
||||
"reveal.js": "~3.9.2",
|
||||
"script-loader": "~0.7.2",
|
||||
"select2": "~3.5.2-browserify",
|
||||
"sinon": "~7.3.2",
|
||||
"socket.io-client": "~2.2.0",
|
||||
"spin.js": "~4.0.0",
|
||||
"standard": "~13.1.0",
|
||||
"store": "~2.0.12",
|
||||
"string-loader": "~0.0.1",
|
||||
"style-loader": "~0.23.1",
|
||||
"tedious": "~6.2.0",
|
||||
"turndown": "~5.0.3",
|
||||
"typo-js": "^1.0.3",
|
||||
"uglifyjs-webpack-plugin": "~1.2.7",
|
||||
"url-loader": "~1.0.1",
|
||||
"vega": "~5.9.1",
|
||||
"vega-embed": "~6.2.2",
|
||||
"vega-lite": "~4.4.0",
|
||||
"velocity-animate": "~1.5.2",
|
||||
"visibilityjs": "~2.0.2",
|
||||
"viz.js": "~2.1.2",
|
||||
"webpack": "~4.39.0",
|
||||
"webpack-cli": "~3.3.6",
|
||||
"webpack-merge": "~4.2.1",
|
||||
"webpack-parallel-uglify-plugin": "~1.1.0"
|
||||
"webpack-parallel-uglify-plugin": "~1.1.0",
|
||||
"wurl": "~2.5.3",
|
||||
"xss": "~1.0.6"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"bufferutil": "~4.0.0",
|
||||
|
|
Loading…
Reference in New Issue