Skip to content

best way to save what you love

implemented esbuild and cleaned up stuff

wukko22c16b2fc858
diff --git a/.gitignore b/.gitignore
index 75454837..01d4a695 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,9 @@
+# npm
node_modules
package-lock.json
+
+# secrets
.env
+
+# esbuild
+min
\ No newline at end of file
diff --git a/README.md b/README.md
index 281ee695..429219b3 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ cobalt doesn't remux any videos, so you get videos of max quality available (unl
- [ ] Instagram support
- [ ] Quality switching for bilibili and Twitter
- [ ] Language picker in settings
-- [ ] Use esmbuild to minify frontend css and js
+- [ ] Make cobalt fully PWA compatible (add a service worker)
- [ ] Make switch buttons in settings selectable with keyboard
- [ ] Remake page rendering module to be more versatile
- [ ] Matching could be redone, I'll see what I can do
diff --git a/package.json b/package.json
index 2d997571..0f390d85 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "cobalt",
"description": "probably the friendliest social media downloader yet",
- "version": "2.2.6",
+ "version": "2.2.7",
"author": "wukko",
"exports": "./src/cobalt.js",
"type": "module",
@@ -24,6 +24,7 @@
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.0.1",
+ "esbuild": "^0.14.51",
"express": "^4.17.1",
"express-rate-limit": "^6.3.0",
"ffmpeg-static": "^5.0.0",
diff --git a/src/cobalt.js b/src/cobalt.js
index 2fc2c0b6..f1458d0f 100644
--- a/src/cobalt.js
+++ b/src/cobalt.js
@@ -13,6 +13,7 @@ import { apiJSON, languageCode } from "./modules/sub/utils.js";
import { Bright, Cyan } from "./modules/sub/consoleText.js";
import stream from "./modules/stream/stream.js";
import loc from "./localization/manager.js";
+import { buildFront } from "./modules/build.js";
const commitHash = shortCommit();
const app = express();
@@ -39,9 +40,11 @@ if (fs.existsSync('./.env')) {
}
})
+ await buildFront();
app.use('/api/', apiLimiter);
app.use('/api/stream', apiLimiterStream);
- app.use('/', express.static('./src/static'));
+ app.use('/', express.static('./min'));
+ app.use('/', express.static('./src/front'));
app.use((req, res, next) => {
try {
diff --git a/src/static/cobalt.css b/src/front/cobalt.css
similarity index 100%
rename from src/static/cobalt.css
rename to src/front/cobalt.css
diff --git a/src/static/cobalt.js b/src/front/cobalt.js
similarity index 100%
rename from src/static/cobalt.js
rename to src/front/cobalt.js
diff --git a/src/static/fonts/notosansmono/notosansmono_3dVQ.woff2 b/src/front/fonts/files/notosansmono_3dVQ.woff2
similarity index 100%
rename from src/static/fonts/notosansmono/notosansmono_3dVQ.woff2
rename to src/front/fonts/files/notosansmono_3dVQ.woff2
diff --git a/src/static/fonts/notosansmono/notosansmono_7dVXQQ.woff2 b/src/front/fonts/files/notosansmono_7dVXQQ.woff2
similarity index 100%
rename from src/static/fonts/notosansmono/notosansmono_7dVXQQ.woff2
rename to src/front/fonts/files/notosansmono_7dVXQQ.woff2
diff --git a/src/static/fonts/notosansmono/notosansmono_DdVXQQ.woff2 b/src/front/fonts/files/notosansmono_DdVXQQ.woff2
similarity index 100%
rename from src/static/fonts/notosansmono/notosansmono_DdVXQQ.woff2
rename to src/front/fonts/files/notosansmono_DdVXQQ.woff2
diff --git a/src/static/fonts/notosansmono/notosansmono_HdVXQQ.woff2 b/src/front/fonts/files/notosansmono_HdVXQQ.woff2
similarity index 100%
rename from src/static/fonts/notosansmono/notosansmono_HdVXQQ.woff2
rename to src/front/fonts/files/notosansmono_HdVXQQ.woff2
diff --git a/src/static/fonts/notosansmono/notosansmono_LdVXQQ.woff2 b/src/front/fonts/files/notosansmono_LdVXQQ.woff2
similarity index 100%
rename from src/static/fonts/notosansmono/notosansmono_LdVXQQ.woff2
rename to src/front/fonts/files/notosansmono_LdVXQQ.woff2
diff --git a/src/static/fonts/notosansmono/notosansmono_PdVXQQ.woff2 b/src/front/fonts/files/notosansmono_PdVXQQ.woff2
similarity index 100%
rename from src/static/fonts/notosansmono/notosansmono_PdVXQQ.woff2
rename to src/front/fonts/files/notosansmono_PdVXQQ.woff2
diff --git a/src/static/fonts/notosansmono/notosansmono_ndVXQQ.woff2 b/src/front/fonts/files/notosansmono_ndVXQQ.woff2
similarity index 100%
rename from src/static/fonts/notosansmono/notosansmono_ndVXQQ.woff2
rename to src/front/fonts/files/notosansmono_ndVXQQ.woff2
diff --git a/src/front/fonts/notosansmono.css b/src/front/fonts/notosansmono.css
new file mode 100644
index 00000000..827b4f61
--- /dev/null
+++ b/src/front/fonts/notosansmono.css
@@ -0,0 +1 @@
+@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('files/notosansmono_DdVXQQ.woff2') format('woff2');unicode-range:U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('files/notosansmono_ndVXQQ.woff2') format('woff2');unicode-range:U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('files/notosansmono_HdVXQQ.woff2') format('woff2');unicode-range:U+1F00-1FFF}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('files/notosansmono_7dVXQQ.woff2') format('woff2');unicode-range:U+0370-03FF}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('files/notosansmono_LdVXQQ.woff2') format('woff2');unicode-range:U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('files/notosansmono_PdVXQQ.woff2') format('woff2');unicode-range:U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('files/notosansmono_3dVQ.woff2') format('woff2');unicode-range:U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD}
\ No newline at end of file
diff --git a/src/static/icons/android-chrome-192x192.png b/src/front/icons/android-chrome-192x192.png
similarity index 100%
rename from src/static/icons/android-chrome-192x192.png
rename to src/front/icons/android-chrome-192x192.png
diff --git a/src/static/icons/android-chrome-512x512.png b/src/front/icons/android-chrome-512x512.png
similarity index 100%
rename from src/static/icons/android-chrome-512x512.png
rename to src/front/icons/android-chrome-512x512.png
diff --git a/src/static/icons/apple-touch-icon.png b/src/front/icons/apple-touch-icon.png
similarity index 100%
rename from src/static/icons/apple-touch-icon.png
rename to src/front/icons/apple-touch-icon.png
diff --git a/src/static/icons/favicon-16x16.png b/src/front/icons/favicon-16x16.png
similarity index 100%
rename from src/static/icons/favicon-16x16.png
rename to src/front/icons/favicon-16x16.png
diff --git a/src/static/icons/favicon-32x32.png b/src/front/icons/favicon-32x32.png
similarity index 100%
rename from src/static/icons/favicon-32x32.png
rename to src/front/icons/favicon-32x32.png
diff --git a/src/static/icons/favicon.ico b/src/front/icons/favicon.ico
similarity index 100%
rename from src/static/icons/favicon.ico
rename to src/front/icons/favicon.ico
diff --git a/src/static/icons/generic.png b/src/front/icons/generic.png
similarity index 100%
rename from src/static/icons/generic.png
rename to src/front/icons/generic.png
diff --git a/src/static/icons/maskable/x128.png b/src/front/icons/maskable/x128.png
similarity index 100%
rename from src/static/icons/maskable/x128.png
rename to src/front/icons/maskable/x128.png
diff --git a/src/static/icons/maskable/x1280.png b/src/front/icons/maskable/x1280.png
similarity index 100%
rename from src/static/icons/maskable/x1280.png
rename to src/front/icons/maskable/x1280.png
diff --git a/src/static/icons/maskable/x192.png b/src/front/icons/maskable/x192.png
similarity index 100%
rename from src/static/icons/maskable/x192.png
rename to src/front/icons/maskable/x192.png
diff --git a/src/static/icons/maskable/x384.png b/src/front/icons/maskable/x384.png
similarity index 100%
rename from src/static/icons/maskable/x384.png
rename to src/front/icons/maskable/x384.png
diff --git a/src/static/icons/maskable/x48.png b/src/front/icons/maskable/x48.png
similarity index 100%
rename from src/static/icons/maskable/x48.png
rename to src/front/icons/maskable/x48.png
diff --git a/src/static/icons/maskable/x512.png b/src/front/icons/maskable/x512.png
similarity index 100%
rename from src/static/icons/maskable/x512.png
rename to src/front/icons/maskable/x512.png
diff --git a/src/static/icons/maskable/x72.png b/src/front/icons/maskable/x72.png
similarity index 100%
rename from src/static/icons/maskable/x72.png
rename to src/front/icons/maskable/x72.png
diff --git a/src/static/icons/maskable/x96.png b/src/front/icons/maskable/x96.png
similarity index 100%
rename from src/static/icons/maskable/x96.png
rename to src/front/icons/maskable/x96.png
diff --git a/src/static/icons/wide.png b/src/front/icons/wide.png
similarity index 100%
rename from src/static/icons/wide.png
rename to src/front/icons/wide.png
diff --git a/src/front/manifest.webmanifest b/src/front/manifest.webmanifest
new file mode 100644
index 00000000..8cd571e5
--- /dev/null
+++ b/src/front/manifest.webmanifest
@@ -0,0 +1 @@
+{"name":"cobalt","short_name":"cobalt","start_url":"/","icons":[{"src":"/icons/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/icons/android-chrome-512x512.png","sizes":"512x512","type":"image/png"},{"src":"/icons/generic.png","sizes":"512x512","type":"image/png","purpose":"any"},{"src":"/icons/maskable/x48.png","sizes":"48x48","type":"image/png","purpose":"maskable"},{"src":"/icons/maskable/x72.png","sizes":"72x72","type":"image/png","purpose":"maskable"},{"src":"/icons/maskable/x96.png","sizes":"96x96","type":"image/png","purpose":"maskable"},{"src":"/icons/maskable/x128.png","sizes":"128x128","type":"image/png","purpose":"maskable"},{"src":"/icons/maskable/x192.png","sizes":"192x192","type":"image/png","purpose":"maskable"},{"src":"/icons/maskable/x384.png","sizes":"384x384","type":"image/png","purpose":"maskable"},{"src":"/icons/maskable/x512.png","sizes":"512x512","type":"image/png","purpose":"maskable"},{"src":"/icons/maskable/x1280.png","sizes":"1280x1280","type":"image/png","purpose":"maskable"}],"theme_color":"#000000","background_color":"#000000","display":"standalone"}
\ No newline at end of file
diff --git a/src/static/robots.txt b/src/front/robots.txt
similarity index 100%
rename from src/static/robots.txt
rename to src/front/robots.txt
diff --git a/src/modules/build.js b/src/modules/build.js
new file mode 100644
index 00000000..a1f9a9cd
--- /dev/null
+++ b/src/modules/build.js
@@ -0,0 +1,14 @@
+import * as esbuild from "esbuild";
+
+export async function buildFront() {
+ try {
+ await esbuild.build({
+ entryPoints: ['src/front/cobalt.js', 'src/front/cobalt.css'],
+ outdir: `min/`,
+ minify: true,
+ loader: {".js": "js", ".css": "css"}
+ })
+ } catch (e) {
+ return;
+ }
+}
diff --git a/src/modules/pageRender.js b/src/modules/pageRender.js
index 274f8b9b..7e9b3fa4 100644
--- a/src/modules/pageRender.js
+++ b/src/modules/pageRender.js
@@ -46,9 +46,9 @@ export default function(obj) {
<link rel="icon" type="image/png" sizes="16x16" href="icons/favicon-16x16.png" />
<link rel="apple-touch-icon" sizes="180x180" href="icons/apple-touch-icon.png" />
- <link rel="manifest" href="cobalt.webmanifest" />
+ <link rel="manifest" href="manifest.webmanifest" />
<link rel="stylesheet" href="cobalt.css" />
- <link rel="stylesheet" href="fonts/notosansmono/notosansmono.css" />
+ <link rel="stylesheet" href="fonts/notosansmono.css" />
<noscript><div style="margin: 2rem;">${loc(obj.lang, 'NoScriptMessage')}</div></noscript>
</head>
diff --git a/src/static/cobalt.webmanifest b/src/static/cobalt.webmanifest
deleted file mode 100644
index c26bac4c..00000000
--- a/src/static/cobalt.webmanifest
+++ /dev/null
@@ -1,64 +0,0 @@
-{
- "name": "cobalt",
- "short_name": "cobalt",
- "start_url": "/",
- "icons": [
- {
- "src": "/icons/android-chrome-192x192.png",
- "sizes": "192x192",
- "type": "image/png"
- }, {
- "src": "/icons/android-chrome-512x512.png",
- "sizes": "512x512",
- "type": "image/png"
- }, {
- "src": "/icons/generic.png",
- "sizes": "512x512",
- "type": "image/png",
- "purpose": "any"
- }, {
- "src": "/icons/maskable/x48.png",
- "sizes": "48x48",
- "type": "image/png",
- "purpose": "maskable"
- }, {
- "src": "/icons/maskable/x72.png",
- "sizes": "72x72",
- "type": "image/png",
- "purpose": "maskable"
- }, {
- "src": "/icons/maskable/x96.png",
- "sizes": "96x96",
- "type": "image/png",
- "purpose": "maskable"
- }, {
- "src": "/icons/maskable/x128.png",
- "sizes": "128x128",
- "type": "image/png",
- "purpose": "maskable"
- }, {
- "src": "/icons/maskable/x192.png",
- "sizes": "192x192",
- "type": "image/png",
- "purpose": "maskable"
- }, {
- "src": "/icons/maskable/x384.png",
- "sizes": "384x384",
- "type": "image/png",
- "purpose": "maskable"
- }, {
- "src": "/icons/maskable/x512.png",
- "sizes": "512x512",
- "type": "image/png",
- "purpose": "maskable"
- }, {
- "src": "/icons/maskable/x1280.png",
- "sizes": "1280x1280",
- "type": "image/png",
- "purpose": "maskable"
- }
- ],
- "theme_color": "#000000",
- "background_color": "#000000",
- "display": "standalone"
-}
\ No newline at end of file
diff --git a/src/static/fonts/notosansmono/notosansmono.css b/src/static/fonts/notosansmono/notosansmono.css
deleted file mode 100644
index f87ca7f5..00000000
--- a/src/static/fonts/notosansmono/notosansmono.css
+++ /dev/null
@@ -1 +0,0 @@
-@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('notosansmono_DdVXQQ.woff2') format('woff2');unicode-range:U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('notosansmono_ndVXQQ.woff2') format('woff2');unicode-range:U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('notosansmono_HdVXQQ.woff2') format('woff2');unicode-range:U+1F00-1FFF}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('notosansmono_7dVXQQ.woff2') format('woff2');unicode-range:U+0370-03FF}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('notosansmono_LdVXQQ.woff2') format('woff2');unicode-range:U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('notosansmono_PdVXQQ.woff2') format('woff2');unicode-range:U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF}@font-face{font-family:'Noto Sans Mono';font-style:normal;font-weight:500;font-stretch:100%;font-display:swap;src:url('notosansmono_3dVQ.woff2') format('woff2');unicode-range:U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD}
\ No newline at end of file