Skip to content

Commit

Permalink
Merge pull request #4 from sehyun-hwang/vite2esbuild
Browse files Browse the repository at this point in the history
Vite2esbuild
  • Loading branch information
sehyun-hwang authored Apr 2, 2023
2 parents 911109f + 37315e2 commit aa29028
Show file tree
Hide file tree
Showing 15 changed files with 1,266 additions and 5,883 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules/
build
dist.js

*.log
7 changes: 4 additions & 3 deletions express/index.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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([
Expand All @@ -59,7 +59,8 @@ export const router = Router()

])

.then(([json]) => res.json(json));
.then(([json]) => res.json(json))
.catch(console.log);
}

catch (error) {
Expand Down
1 change: 0 additions & 1 deletion express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions nginx/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
snowpack/build
dist.js

Dockerfile
Dockerfile
8 changes: 3 additions & 5 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions nginx/esbuild/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { fileTypeFromBuffer } from 'file-type/core';
import sanitizeHtml from 'sanitize-html';

export { fileTypeFromBuffer, sanitizeHtml };
1 change: 1 addition & 0 deletions nginx/esbuild/mock-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default null;
31 changes: 31 additions & 0 deletions nginx/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
<title>Real-Time imshow Viewer</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🖼</text></svg>">

<link rel="stylesheet" href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@material/[email protected]/dist/mdc.tab-bar.min.css" />
<style>
html {
padding: 0;
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

#mouse-position {
Expand All @@ -19,6 +23,10 @@
padding: 1rem;
background: white;
}

#subscription-management h3 {
display: inline;
}
</style>
<script type="module" src="./index.js"></script>
</head>
Expand All @@ -32,6 +40,29 @@ <h1>Real-Time <code>imshow</code> Viewer</h1>
<input type="file" onchange="Upload(this)">
</p>

<section>
<h2>Subscription Management</h2>
<ul id="subscription-management">
<li>
<h3><code>/</code></h3>
<input type="checkbox" />
<label for="">Append images</label>
<button>Delete</button>
</li>
</ul>
<button></button>
</section>

<button class="mdc-tab" role="tab" aria-selected="false" tabindex="-1">
<span class="mdc-tab__content">
<span class="mdc-tab__text-label">Favorites</span>
<span class="mdc-tab-indicator">
<span class="mdc-tab-indicator__content mdc-tab-indicator__content--underline"></span>
</span>
</span>
<span class="mdc-tab__ripple"></span>
</button>

<img id="initial" class="content" src="https://proxy.hwangsehyun.com/imshow/last">
</body>

Expand Down
9 changes: 6 additions & 3 deletions nginx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import WebSocket from 'https://cdn.jsdelivr.net/npm/[email protected]
import { WordArray } from 'https://cdn.jsdelivr.net/npm/[email protected]/lib/core.js';
import { MD5 } from 'https://cdn.jsdelivr.net/npm/[email protected]/lib/md5.js';

import { fromStream } from './snowpack/build/index.js';
import { fileTypeFromBuffer } from './esbuild/dist.js';
import { onMouseMove, SUB_URL } from './misc.js';
//import { MDCTabBar } from 'https://cdn.jsdelivr.net/npm/@material/[email protected]/dist/mdc.tabBar.min.js/+esm'

//const tabBar = new MDCTabBar(document.querySelector('.mdc-tab-bar'));

const selectHashElement = hash => {
const elements = document.querySelectorAll(`.content[data-hash="${hash}"]`);
Expand All @@ -29,7 +32,7 @@ websocket.addEventListener('message', ({ data }) => Promise.resolve(data)
}, () => fetch('data:image/png;base64,' + data)

.then(async res => {
const type = await fromStream(res.clone().body)
const type = await fileTypeFromBuffer(await res.clone().arrayBuffer())
.then(result => result ? result.mime : 'image/svg+xml');
const buffer = await res.arrayBuffer();
const blob = new Blob([buffer], { type });
Expand Down Expand Up @@ -76,7 +79,7 @@ websocket.addEventListener('message', ({ data }) => Promise.resolve(data)
}
}
child ? child.after(newElement) : document.body.appendChild(newElement);
window.scrollTo(0, document.body.scrollHeight);
//window.scrollTo(0, document.body.scrollHeight);
})
.catch(console.error)

Expand Down
9 changes: 5 additions & 4 deletions nginx/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"type": "module",
"scripts": {
"build": "snowpack build"
"build": "cd esbuild && esbuild lib.js --bundle --format=esm --alias:node:buffer=buffer --alias:node:stream=./mock-stream.js --outfile=./dist.js"
},
"devDependencies": {
"file-type": "^16.5.3",
"sanitize-html": "^2.5.1",
"snowpack": "^3.8.8"
"buffer": "^6.0.3",
"esbuild": "^0.17.14",
"file-type": "^18.2.1",
"sanitize-html": "^2.5.1"
}
}
Loading

0 comments on commit aa29028

Please sign in to comment.