mirror of
https://github.com/gigirassy/plaster.git
synced 2024-12-24 10:49:07 +00:00
Compare commits
No commits in common. "68e701dd2186043881ee0be735e28992cb30da17" and "e2c1fdb3833555568d8957198e806b439e3368ce" have entirely different histories.
68e701dd21
...
e2c1fdb383
@ -2,10 +2,6 @@
|
|||||||
Fetches raw data and displays it. Took like 20 minutes to make the first build.
|
Fetches raw data and displays it. Took like 20 minutes to make the first build.
|
||||||
It's extremely simple, so it's under CC0. If you want to improve it, simply submit a pull request.
|
It's extremely simple, so it's under CC0. If you want to improve it, simply submit a pull request.
|
||||||
That's all.
|
That's all.
|
||||||
Disclaimer: The first build was made using a language learning model, and then significantly tweaked by a human being (me). This might be outside of people's comfort zones, so I'd thought it'd be important to note this.
|
|
||||||
## To do:
|
|
||||||
* Implement (togglable!) fetching of paste views, creator usernames, favorites, and expiration/creation dates.
|
|
||||||
* Togglable, just-for-fun ASCII art of TFA characters on front page bottom-right corner. Owners can also change this ASCII art by mounting TXT files as a volume.
|
|
||||||
### Instances
|
### Instances
|
||||||
| link | country | notes |
|
| link | country | notes |
|
||||||
|---------------------------|---------|-------------------|
|
|---------------------------|---------|-------------------|
|
||||||
|
8
app.js
8
app.js
@ -1,18 +1,10 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const cookieParser = require('cookie-parser');
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
||||||
app.use(express.static('public'));
|
app.use(express.static('public'));
|
||||||
app.use(cookieParser());
|
|
||||||
|
|
||||||
const autoCopyDefault = process.env.AUTO_COPY_DEFAULT === 'true';
|
|
||||||
|
|
||||||
app.get('/auto-copy-default', (req, res) => {
|
|
||||||
res.json({ autoCopyDefault });
|
|
||||||
});
|
|
||||||
|
|
||||||
// Route to handle raw Pastebin requests
|
// Route to handle raw Pastebin requests
|
||||||
app.get('/:pasteId', async (req, res) => {
|
app.get('/:pasteId', async (req, res) => {
|
||||||
|
@ -5,7 +5,5 @@ services:
|
|||||||
image: ghcr.io/gigirassy/plaster
|
image: ghcr.io/gigirassy/plaster
|
||||||
ports:
|
ports:
|
||||||
- "35200:3000" # change host port if needed
|
- "35200:3000" # change host port if needed
|
||||||
environment:
|
|
||||||
AUTO_COPY_DEFAULT: "false" # if enabled, this will automatically copy paste contents to the clipboard on main page
|
|
||||||
restart: always
|
restart: always
|
||||||
container_name: plaster
|
container_name: plaster
|
||||||
|
@ -12,11 +12,10 @@
|
|||||||
"nodejs",
|
"nodejs",
|
||||||
"express"
|
"express"
|
||||||
],
|
],
|
||||||
"author": "nune",
|
"author": "Your Name",
|
||||||
"license": "CC0",
|
"license": "CC0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"node-fetch": "^2.6.7",
|
"node-fetch": "^2.6.7"
|
||||||
"cookie-parser": "^1.4.7"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,79 +1,23 @@
|
|||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.getElementById('fetchBtn').addEventListener('click', () => {
|
||||||
const fetchBtn = document.getElementById('fetchBtn');
|
const urlInput = document.getElementById('pasteUrl').value;
|
||||||
const pasteUrlInput = document.getElementById('pasteUrl');
|
|
||||||
const autoCopyCheckbox = document.getElementById('autoCopyCheckbox');
|
|
||||||
|
|
||||||
// Load default state for the checkbox
|
// Extract the Paste ID from the provided Pastebin URL
|
||||||
const defaultAutoCopy = await getDefaultAutoCopy();
|
const pasteId = getPasteId(urlInput);
|
||||||
const userPreference = getCookie('autoCopyEnabled');
|
|
||||||
autoCopyCheckbox.checked = userPreference !== null ? userPreference === 'true' : defaultAutoCopy;
|
|
||||||
|
|
||||||
// Save user preference to a cookie when the checkbox changes
|
if (pasteId) {
|
||||||
autoCopyCheckbox.addEventListener('change', () => {
|
window.location.href = `/${pasteId}`;
|
||||||
setCookie('autoCopyEnabled', autoCopyCheckbox.checked, 365);
|
} else {
|
||||||
});
|
alert('Please enter a valid Pastebin URL.');
|
||||||
|
}
|
||||||
// Handle "Go to Raw Paste" button click
|
|
||||||
fetchBtn.addEventListener('click', async () => {
|
|
||||||
const urlInput = pasteUrlInput.value.trim();
|
|
||||||
const pasteId = getPasteId(urlInput);
|
|
||||||
|
|
||||||
if (!pasteId) {
|
|
||||||
alert('Please enter a valid Pastebin URL.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const frontendUrl = `/${pasteId}`;
|
|
||||||
|
|
||||||
// If auto-copy is enabled, fetch and copy the paste contents
|
|
||||||
if (autoCopyCheckbox.checked) {
|
|
||||||
try {
|
|
||||||
const response = await fetch(frontendUrl);
|
|
||||||
if (response.ok) {
|
|
||||||
const pasteContents = await response.text();
|
|
||||||
await navigator.clipboard.writeText(pasteContents);
|
|
||||||
alert('Raw paste contents copied to clipboard!');
|
|
||||||
} else {
|
|
||||||
alert('Failed to fetch paste contents.');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
alert('Error copying to clipboard: ' + error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect to the frontend paste URL
|
|
||||||
window.location.href = frontendUrl;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Utility function to get the default auto-copy value from the server
|
|
||||||
async function getDefaultAutoCopy() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/auto-copy-default');
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
return data.autoCopyDefault;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching auto-copy default:', error);
|
|
||||||
}
|
|
||||||
return false; // Default fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract Paste ID from the given Pastebin URL
|
|
||||||
function getPasteId(url) {
|
function getPasteId(url) {
|
||||||
|
// Check if the URL is a valid Pastebin URL and extract the Paste ID
|
||||||
const regex = /pastebin\.com\/(?:raw\/)?([a-zA-Z0-9]+)/;
|
const regex = /pastebin\.com\/(?:raw\/)?([a-zA-Z0-9]+)/;
|
||||||
const match = url.match(regex);
|
const match = url.match(regex);
|
||||||
return match ? match[1] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Utility functions to manage cookies
|
if (match) {
|
||||||
function setCookie(name, value, days) {
|
return match[1]; // Return the Paste ID
|
||||||
const expires = new Date(Date.now() + days * 86400000).toUTCString();
|
}
|
||||||
document.cookie = `${name}=${value}; expires=${expires}; path=/`;
|
return null; // Invalid Pastebin URL
|
||||||
}
|
|
||||||
|
|
||||||
function getCookie(name) {
|
|
||||||
const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
|
|
||||||
return match ? decodeURIComponent(match[1]) : null;
|
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,6 @@
|
|||||||
<p>All issues regarding paste content should be reported to <a href="https://pastebin.com">Pastebin</a>. In addition, if you want a real alternative to Pastebin, <a href="https://privatebin.info">check out Privatebin!</a></p>
|
<p>All issues regarding paste content should be reported to <a href="https://pastebin.com">Pastebin</a>. In addition, if you want a real alternative to Pastebin, <a href="https://privatebin.info">check out Privatebin!</a></p>
|
||||||
<input type="text" id="pasteUrl" placeholder="Enter Pastebin URL">
|
<input type="text" id="pasteUrl" placeholder="Enter Pastebin URL">
|
||||||
<button id="fetchBtn">go!</button>
|
<button id="fetchBtn">go!</button>
|
||||||
<label>
|
|
||||||
<input type="checkbox" id="autoCopyCheckbox">
|
|
||||||
auto-copy paste contents?
|
|
||||||
</label>
|
|
||||||
<script src="client.js" defer></script>
|
<script src="client.js" defer></script>
|
||||||
<p><a href="https://github.com/gigirassy/plaster">source code</a> is licensed under the public domain</p></div>
|
<p><a href="https://github.com/gigirassy/plaster">source code</a> is licensed under the public domain</p></div>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user