diff --git a/.gitignore b/.gitignore index a1494e3..2e89448 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules/ -build +dist.js *.log \ No newline at end of file diff --git a/express/index.js b/express/index.js index fd0bca7..c4e8011 100644 --- a/express/index.js +++ b/express/index.js @@ -1,9 +1,9 @@ import { userInfo as getUserInfo } from "os"; import { createHash } from 'crypto'; +import { buffer as stream2buffer } from 'stream/consumers'; import { Router } from 'express'; import got from 'got'; -import { streamToBuffer } from '@jorgeferrero/stream-to-buffer'; import { Base64Encode } from 'base64-stream'; const { uid } = getUserInfo(); @@ -37,7 +37,7 @@ export const router = Router() const { date } = req.query; type = _type; - streamToBuffer(req).then(_buffer => buffer = _buffer); + stream2buffer(req).then(_buffer => buffer = _buffer); try { Promise.all([ @@ -59,7 +59,8 @@ export const router = Router() ]) - .then(([json]) => res.json(json)); + .then(([json]) => res.json(json)) + .catch(console.log); } catch (error) { diff --git a/express/package.json b/express/package.json index 498acf4..70c657b 100644 --- a/express/package.json +++ b/express/package.json @@ -5,7 +5,6 @@ "curl-svg": "curl --data-binary @/mnt/plantym/news-title/result.svg -H 'Content-Type: image/svg+xml' localhost:8080/imshow?date=`date -Ins | sed 's/\\+/%2B/; s/\\,/\\./'`" }, "dependencies": { - "@jorgeferrero/stream-to-buffer": "^2.0.6", "base64-stream": "^1.0.0", "express": "^4.17.3", "got": "^12.0.2" diff --git a/nginx/.dockerignore b/nginx/.dockerignore index 0ea043f..4c9fbb8 100644 --- a/nginx/.dockerignore +++ b/nginx/.dockerignore @@ -1,4 +1,4 @@ node_modules -snowpack/build +dist.js -Dockerfile \ No newline at end of file +Dockerfile diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 61a649f..bcae7de 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,17 +1,15 @@ FROM node:alpine as build WORKDIR /mnt -COPY package.json yarn.lock ./ +COPY package.json ./ RUN yarn -COPY snowpack.config.json ./ -COPY snowpack/index.js snowpack/ - +COPY esbuild ./esbuild RUN yarn build FROM shurco/nginx-push-stream-module COPY . /var/www/html -COPY --from=build /mnt/snowpack/build /var/www/html/snowpack/build +COPY --from=build /mnt/esbuild/dist.js /var/www/html/esbuild/dist.js LABEL org.opencontainers.image.source https://github.com/sehyun-hwang/imshow \ No newline at end of file diff --git a/nginx/esbuild/lib.js b/nginx/esbuild/lib.js new file mode 100644 index 0000000..f618a5e --- /dev/null +++ b/nginx/esbuild/lib.js @@ -0,0 +1,4 @@ +import { fileTypeFromBuffer } from 'file-type/core'; +import sanitizeHtml from 'sanitize-html'; + +export { fileTypeFromBuffer, sanitizeHtml }; diff --git a/nginx/esbuild/mock-stream.js b/nginx/esbuild/mock-stream.js new file mode 100644 index 0000000..4b0f9fb --- /dev/null +++ b/nginx/esbuild/mock-stream.js @@ -0,0 +1 @@ +export default null; \ No newline at end of file diff --git a/nginx/index.html b/nginx/index.html index 4ce9526..37b3545 100644 --- a/nginx/index.html +++ b/nginx/index.html @@ -7,9 +7,13 @@
imshow
Viewer/