Skip to content

Commit

Permalink
Merge pull request #21 from socraticDevBlog/addpastebin
Browse files Browse the repository at this point in the history
adding pastebin
  • Loading branch information
socraticDevBlog authored Jan 1, 2024
2 parents 0472914 + 2730d2c commit e2f3c4f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions _imports/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<a id="project-link" class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">Projects</a>
<div class="dropdown-menu" aria-labelledby="dropdown04">
<a class="dropdown-item" href="pastebin.html">pastebin</a>
<a class="dropdown-item"
href="https://dailybuild.org/CyberChef_v10.4.0/CyberChef_v10.4.0.html">cyberchef</a>
<a class="dropdown-item" href="https://dailybuild.org/gemini/">gemini capsule</a>
Expand Down
89 changes: 89 additions & 0 deletions pastebin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<sergey-import src="header">
<title>dailybuild pastebin;#dailybuild</title>
</sergey-import>
<div class="project row slider-text align-items-center justify-content-center" style="padding-top: 80px;"></div>

<h1 style="color: orange;">poor man cloud-native pastebin</h1>
<div style="margin-left: 10em">
<p>You can either upload some text pasted to the textbox area or a file</p>
<textarea id="textInput" placeholder="Paste text here (keep empty if you woona upload a file)"></textarea>
<button onclick="uploadData()">Upload Data to Pastebin</button>
<p style="margin-top: 5em">
... or upload a text file (kode?)
<input type="file" id="fileInput" />

</p>

<p>
<div id="responseContainer"></div>
</p>
</div>

<script>
async function uploadData() {
const textInput = document.getElementById("textInput");
const fileInput = document.getElementById("fileInput");
const textData = textInput.value;
const file = fileInput.files[0];
const BaseURL = "https://paste.socratic.dev/paste";

let content;

if (textData) {
content = textData;
} else if (file) {
const reader = new FileReader();
content = await new Promise((resolve) => {
reader.onload = function (e) {
resolve(e.target.result);
};
reader.readAsText(file);
});
} else {
alert("Please enter text or select a file.");
return;
}

// Create a JSON object with "content" as the key
const data = {
content: content,
};

// Convert the JSON object to a string
const jsonData = JSON.stringify(data);

// Send the data to the API using the fetch API
try {
const response = await fetch(BaseURL, {
method: "POST",
headers: {
accept: "application/json",
"Content-Type": "application/json",
},
body: jsonData,
});

const result = await response.json();

// Display the API response on the web page
const responseContainer =
document.getElementById("responseContainer");
var id = result["id"];
id = id.replace('"', "");
const url = `${BaseURL}?id=${id}`;
responseContainer.innerHTML = `<p>Visit this URL to view paste: <a href=${url}>${url}</a></p>`;
} catch (error) {
console.error("Error sending data to API:", error);
alert("Error sending data to API.");
}
}
</script>
<div style="margin-top: 260px;">
<sergey-import src="footer">
<a href="dpro-comic.html#top" title="Back to top">
</sergey-import>
<sergey-import src="scripts" />
</div>
</body>
</html>

0 comments on commit e2f3c4f

Please sign in to comment.