mirror of
https://github.com/gigirassy/plaster.git
synced 2024-12-23 18:39:07 +00:00
Compare commits
13 Commits
e2c1fdb383
...
68e701dd21
Author | SHA1 | Date | |
---|---|---|---|
|
68e701dd21 | ||
|
6c123e39ae | ||
|
0328c8fb4b | ||
|
71fc7aab22 | ||
|
3ac7f784af | ||
|
4daf9bcb78 | ||
|
1021a81f1c | ||
|
b5e185ab6b | ||
|
7a1cb27f5b | ||
|
3be15e71cb | ||
|
24b0d577e9 | ||
|
4e25322071 | ||
|
7cfdc5ba03 |
@ -2,6 +2,10 @@
|
|||||||
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,10 +1,18 @@
|
|||||||
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,5 +5,7 @@ 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,10 +12,11 @@
|
|||||||
"nodejs",
|
"nodejs",
|
||||||
"express"
|
"express"
|
||||||
],
|
],
|
||||||
"author": "Your Name",
|
"author": "nune",
|
||||||
"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,23 +1,79 @@
|
|||||||
document.getElementById('fetchBtn').addEventListener('click', () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
const urlInput = document.getElementById('pasteUrl').value;
|
const fetchBtn = document.getElementById('fetchBtn');
|
||||||
|
const pasteUrlInput = document.getElementById('pasteUrl');
|
||||||
|
const autoCopyCheckbox = document.getElementById('autoCopyCheckbox');
|
||||||
|
|
||||||
// Extract the Paste ID from the provided Pastebin URL
|
// Load default state for the checkbox
|
||||||
|
const defaultAutoCopy = await getDefaultAutoCopy();
|
||||||
|
const userPreference = getCookie('autoCopyEnabled');
|
||||||
|
autoCopyCheckbox.checked = userPreference !== null ? userPreference === 'true' : defaultAutoCopy;
|
||||||
|
|
||||||
|
// Save user preference to a cookie when the checkbox changes
|
||||||
|
autoCopyCheckbox.addEventListener('change', () => {
|
||||||
|
setCookie('autoCopyEnabled', autoCopyCheckbox.checked, 365);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle "Go to Raw Paste" button click
|
||||||
|
fetchBtn.addEventListener('click', async () => {
|
||||||
|
const urlInput = pasteUrlInput.value.trim();
|
||||||
const pasteId = getPasteId(urlInput);
|
const pasteId = getPasteId(urlInput);
|
||||||
|
|
||||||
if (pasteId) {
|
if (!pasteId) {
|
||||||
window.location.href = `/${pasteId}`;
|
|
||||||
} else {
|
|
||||||
alert('Please enter a valid Pastebin URL.');
|
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;
|
||||||
if (match) {
|
}
|
||||||
return match[1]; // Return the Paste ID
|
|
||||||
}
|
// Utility functions to manage cookies
|
||||||
return null; // Invalid Pastebin URL
|
function setCookie(name, value, days) {
|
||||||
|
const expires = new Date(Date.now() + days * 86400000).toUTCString();
|
||||||
|
document.cookie = `${name}=${value}; expires=${expires}; path=/`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCookie(name) {
|
||||||
|
const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
|
||||||
|
return match ? decodeURIComponent(match[1]) : null;
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,10 @@
|
|||||||
<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