Update path to frontend static files

Signed-off-by: Joe Ma <rikkaneko23@gmail.com>
This commit is contained in:
Joe Ma 2023-11-19 02:50:56 +08:00
parent 3de4fa14ed
commit 2e9a56376d
No known key found for this signature in database
GPG key ID: 7A0ECF5F5EDC587F
7 changed files with 8 additions and 187 deletions

View file

@ -26,7 +26,7 @@
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.9.1/font/bootstrap-icons.min.css" <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.9.1/font/bootstrap-icons.min.css"
rel="stylesheet"> rel="stylesheet">
<link href="css/paste.css" rel="stylesheet"> <link href="/static/paste.css" rel="stylesheet">
</head> </head>
<body> <body>
<nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark" id="navbar"> <nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark" id="navbar">
@ -271,7 +271,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.11.6/umd/popper.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.11.6/umd/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/js/bootstrap.min.js"></script>
<script src="js/paste.js"></script> <script src="/static/paste.js"></script>
</body> </body>
</html> </html>

View file

@ -16,9 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/// <reference path="../../../node_modules/@types/bootstrap/index.d.ts" /> /// <reference path="../../node_modules/@types/bootstrap/index.d.ts" />
const endpoint = 'https://pb.nekoid.cc';
let input_div = { let input_div = {
file: null, file: null,
@ -254,7 +252,7 @@ $(function () {
upload_button.prop('disabled', true); upload_button.prop('disabled', true);
upload_button.text('Uploading...'); upload_button.text('Uploading...');
try { try {
const res = await fetch(endpoint, { const res = await fetch('/', {
method: 'POST', method: 'POST',
body: filtered, body: filtered,
}); });
@ -295,7 +293,7 @@ $(function () {
show_pop_alert('Invalid Paste ID.', 'alert-warning'); show_pop_alert('Invalid Paste ID.', 'alert-warning');
return; return;
} }
window.open(`https://pb.nekoid.cc/${uuid}`); window.open(`/${uuid}`);
}); });
view_btn.on('click', async function () { view_btn.on('click', async function () {
@ -306,7 +304,7 @@ $(function () {
} }
try { try {
const res = await fetch(`${endpoint}/${uuid}/settings?${new URLSearchParams({ json: '1' })}`); const res = await fetch(`/${uuid}/settings?${new URLSearchParams({ json: '1' })}`);
if (res.ok) { if (res.ok) {
const paste_info = await res.json(); const paste_info = await res.json();
build_paste_modal(paste_info, show_qrcode, false); build_paste_modal(paste_info, show_qrcode, false);

View file

@ -1,3 +1,3 @@
export const SERVICE_URL = 'pb.nekoid.cc'; export const SERVICE_URL = 'pb.nekoid.cc';
export const PASTE_WEB_URL = 'https://raw.githubusercontent.com/rikkaneko/paste/main/static/v2'; export const PASTE_WEB_URL = 'https://raw.githubusercontent.com/rikkaneko/paste/main/frontend';
export const UUID_LENGTH = 4; export const UUID_LENGTH = 4;

View file

@ -56,7 +56,7 @@ router.get('/favicon.ico', () => {
}); });
// Web script and style file // Web script and style file
router.get('/(css|js)/*', (request) => { router.get('/static/*', (request) => {
const { url } = request; const { url } = request;
const { pathname } = new URL(url); const { pathname } = new URL(url);
const path = pathname.replace(/\/+$/, '') || '/'; const path = pathname.replace(/\/+$/, '') || '/';

View file

@ -1,177 +0,0 @@
<!--
~ This file is part of paste.
~ Copyright (c) 2022-2023 Joe Ma <rikkaneko23@gmail.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Lesser General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Paste</title>
</head>
<body>
<h2>Paste Service</h2>
<p>
<a href="https://pb.nekoid.cc">pb.nekoid.cc</a> is a pastebin-like service hosted on Cloudflare Worker.<br>
This service is primarily designed for own usage and interest only.<br>
All data may be deleted or expired without any notification and guarantee. Please <b>DO NOT</b> abuse this
service.<br>
The limit for file upload is <b>10 MB</b> and the paste will be kept for <b>28 days</b> only by default.<br>
The source code is available in my GitHub repository <a href="https://github.com/rikkaneko/paste">[here]</a>.<br>
This webpage is designed for upload files only.
For other operations like changing paste settings and deleting paste, please make use of the
<a href="https://github.com/rikkaneko/paste#api-specification">API call</a> with <a
href="https://wiki.archlinux.org/title/CURL">curl</a>.
</p>
<form id="upload_file_form" action="https://pb.nekoid.cc" method="POST" enctype=multipart/form-data>
<div>
<div>
<h4>Upload file</h4>
<input id="upload_file" type="file" name="u" style="font-size: 14px">
</div>
<div>
<h4>Upload text</h4>
<div>
<textarea id="text_input"
style="width: 50%; max-width: 80%; font-size: 14px; margin-top: 2px"
rows="10" name="u" spellcheck="false"></textarea><br>
(<span id="text_length">0 characters</span>)
</div>
</div>
<h4>Settings</h4>
<table style="padding-bottom: 2px;">
<tr>
<td>
<label for="title_input">Title: </label>
</td>
<td>
<input id="title_input" type="text" name="title" spellcheck="false" style="width: 20em">
</td>
</tr>
<tr>
<td>
<label for="pass_input">Password: </label>
</td>
<td>
<input id="pass_input" type="password" name="pass" style="width: 20em">
<input id="show_pass_button" type="checkbox">
<label for="show_pass_button">Show</label>
</td>
</tr>
<tr>
<td>
<label for="read_limit_input">Read limit: </label>
</td>
<td>
<input id="read_limit_input" type="number" name="read-limit" min="1" style="width: 3em">
</td>
</tr>
</table>
<input id="show_qr_checkbox" type="checkbox" name="qrcode" checked value="1">
<label for="show_qr_checkbox">Show QR code on sumbitted</label>
</div>
<div>
<input id="gen_link" type="checkbox" name="paste-type" value="link">
<label for="gen_link">Generate as shorten URL link</label>
</div>
<br>
<div>
<input id="reset_button" type="reset" value="Reset" style="font-size: 14px">
<input id="sumbit_form_button" type="submit" value="Sumbit" style="font-size: 14px"> (<span
id="file_stats">0 bytes</span>)
</div>
</form>
<script>
function update_textarea() {
const length = document.getElementById('text_length');
length.textContent = `${this.value.length} characters`;
}
function update_file_status() {
const status = document.getElementById('file_stats');
const title = document.getElementById('title_input');
if (this.files[0] === undefined) {
status.textContent = '0 bytes';
return;
}
let bytes = this.files[0]?.size ?? 0;
let size = bytes + ' bytes';
const units = ['KiB', 'MiB', 'GiB', 'TiB'];
for (let i = 0, approx = bytes / 1024; approx > 1; approx /= 1024, i++) {
size = approx.toFixed(3) + ' ' + units[i];
}
title.value = this.files[0]?.name || '';
status.textContent = `${this.files[0]?.type || 'application/octet-stream'}, ${size}`;
}
function toggle_password() {
let input_field = document.getElementById('pass_input');
if (this.checked) {
input_field.type = 'text';
} else {
input_field.type = 'password';
}
}
function reset_form() {
// Re-enable all input elements
let elements = document.getElementById('upload_file_form').elements;
for (let i = 0; i < elements.length; i++) {
elements[i].disabled = false;
}
let size = document.getElementById('file_stats');
size.textContent = '0 bytes';
}
function handle_submit_form(event) {
let elements = this.elements;
let select_file = elements.namedItem('upload_file');
let text = elements.namedItem('text_input');
if (!!select_file.value.length ^ !!text.value.length) {
// Check file size
const size = select_file.files[0]?.size ?? 0;
if (size > 10485760) {
alert('Upload file size must not excess 10 MB.');
event.preventDefault();
return false;
}
for (let i = 0; i < elements.length; i++) {
elements[i].disabled = elements[i].value.length === 0;
}
} else {
alert('You must either upload a file or upload text, but not both or neither.');
// Prevent default submission
event.preventDefault();
}
}
document.getElementById('upload_file').addEventListener('change', update_file_status, false);
document.getElementById('text_input').addEventListener('input', update_textarea, false);
document.getElementById('show_pass_button').addEventListener('change', toggle_password, false);
document.getElementById('reset_button').addEventListener('click', reset_form, false);
document.getElementById('upload_file_form').addEventListener('submit', handle_submit_form, false);
</script>
<br>
<a href="https://nekoid.cc">[Homepage]</a>
<a href="https://github.com/rikkaneko/paste#api-specification">[API]</a>
<a href="https://pb.nekoid.cc">[Switch to new version]</a>
<p>&copy; 2022 rikkaneko</p>
</body>
</html>