Compare commits
10 commits
26cc78334a
...
f603b950de
Author | SHA1 | Date | |
---|---|---|---|
baalajimaestro | f603b950de | ||
baalajimaestro | 683358f3c1 | ||
baalajimaestro | 69a3c01a06 | ||
baalajimaestro | e21c1a73a6 | ||
baalajimaestro | f272a75d6d | ||
baalajimaestro | 3a14d0bc0c | ||
baalajimaestro | 5ec0041b66 | ||
baalajimaestro | af1b8d32be | ||
baalajimaestro | 7f94110428 | ||
baalajimaestro | 4bc688a79d |
27
.gitea/workflows/build-push.yml
Normal file
27
.gitea/workflows/build-push.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
Building:
|
||||
runs-on: native:host
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build & Push
|
||||
uses: docker/build-push-action@master
|
||||
with:
|
||||
push: true
|
||||
context: .
|
||||
platforms: linux/amd64
|
||||
tags: git.baalajimaestro.me/baalajimaestro/obsolute-paste:latest
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
69
Cargo.lock
generated
69
Cargo.lock
generated
|
@ -281,9 +281,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
|||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.21.0"
|
||||
version = "0.21.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
|
||||
checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
|
@ -483,7 +483,7 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
"quote",
|
||||
"scratch",
|
||||
"syn 2.0.15",
|
||||
"syn 2.0.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -500,7 +500,7 @@ checksum = "631569015d0d8d54e6c241733f944042623ab6df7bc3be7466874b05fcdb1c5f"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
"syn 2.0.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -759,9 +759,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "hyper-rustls"
|
||||
version = "0.23.2"
|
||||
version = "0.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c"
|
||||
checksum = "0646026eb1b3eea4cd9ba47912ea5ce9cc07713d105b1a14698f4e6433d348b7"
|
||||
dependencies = [
|
||||
"http",
|
||||
"hyper",
|
||||
|
@ -1161,18 +1161,18 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.56"
|
||||
version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
|
||||
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.26"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
|
||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
@ -1235,9 +1235,9 @@ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
|||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.17"
|
||||
version = "0.11.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13293b639a097af28fc8a90f22add145a9c954e49d77da06263d58cf44d5fb91"
|
||||
checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bytes",
|
||||
|
@ -1298,14 +1298,14 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.20.8"
|
||||
version = "0.21.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f"
|
||||
checksum = "c911ba11bc8433e811ce56fde130ccf32f5127cab0e0194e9c68c5a5b671791e"
|
||||
dependencies = [
|
||||
"log",
|
||||
"ring",
|
||||
"rustls-webpki",
|
||||
"sct",
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1317,6 +1317,16 @@ dependencies = [
|
|||
"base64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-webpki"
|
||||
version = "0.100.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b"
|
||||
dependencies = [
|
||||
"ring",
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.13"
|
||||
|
@ -1362,29 +1372,29 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.162"
|
||||
version = "1.0.183"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71b2f6e1ab5c2b98c05f0f35b236b22e8df7ead6ffbf51d7808da7f8817e7ab6"
|
||||
checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.162"
|
||||
version = "1.0.183"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2a0814352fd64b58489904a44ea8d90cb1a91dcb6b4f5ebabc32c8318e93cb6"
|
||||
checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
"syn 2.0.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.96"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1"
|
||||
checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
@ -1493,9 +1503,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.15"
|
||||
version = "2.0.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
|
||||
checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1504,9 +1514,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tera"
|
||||
version = "1.18.1"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95a665751302f22a03c56721e23094e4dc22b04a80f381e6737a07bf7a7c70c0"
|
||||
checksum = "a5ab29bb4f3e256ae6ad5c3e2775aa1f8829f2c0c101fc407bfd3a6df15c60c5"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"chrono-tz",
|
||||
|
@ -1551,7 +1561,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
"syn 2.0.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1625,13 +1635,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.23.4"
|
||||
version = "0.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59"
|
||||
checksum = "e0d409377ff5b1e3ca6437aa86c1eb7d40c134bfec254e44c830defa92669db5"
|
||||
dependencies = [
|
||||
"rustls",
|
||||
"tokio",
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
10
Cargo.toml
10
Cargo.toml
|
@ -6,9 +6,9 @@ edition = "2021"
|
|||
[dependencies]
|
||||
actix-web = { version = "4.3.1", default-features = false, features = ["macros", "compress-brotli", "compress-gzip", "cookies"]}
|
||||
actix-files = "0.6.2"
|
||||
tera = "1.18.1"
|
||||
serde = { version = "1.0.162", features = ["derive"] }
|
||||
reqwest = { version = "0.11.17", default-features = false, features = ["rustls-tls"] }
|
||||
serde_json = "1.0.96"
|
||||
base64 = "0.21.0"
|
||||
tera = "1.19.0"
|
||||
serde = { version = "1.0.183", features = ["derive"] }
|
||||
reqwest = { version = "0.11.18", default-features = false, features = ["rustls-tls"] }
|
||||
serde_json = "1.0.105"
|
||||
base64 = "0.21.2"
|
||||
mime = "0.3.17"
|
||||
|
|
|
@ -5,6 +5,7 @@ A no-nonsense pastebin, that serves content of files from a private gitlab repos
|
|||
Necessary ENV Variables:
|
||||
|
||||
`GITLAB_TOKEN`: A personal/deploy token, that can read the files in the provided repo
|
||||
|
||||
`BASE_URL`: Base API URL to the repo, example: `https://git.baalajimaestro.me/api/v4/projects/0`
|
||||
|
||||
This project is hostable with docker, and a prebuilt docker image is at `registry.baalajimaestro.me/baalajimaestro/obsolute-paste`
|
||||
|
|
32
src/main.rs
32
src/main.rs
|
@ -24,43 +24,45 @@ struct Paste {
|
|||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct GitLabSuccessJSON {
|
||||
file_name: String,
|
||||
file_path: String,
|
||||
name: String,
|
||||
path: String,
|
||||
size: u64,
|
||||
encoding: String,
|
||||
content_sha256: String,
|
||||
r#ref: String,
|
||||
blob_id: String,
|
||||
commit_id: String,
|
||||
last_commit_id: String,
|
||||
execute_filemode: bool,
|
||||
content: String,
|
||||
sha: String,
|
||||
target: Option<String>,
|
||||
url: String,
|
||||
html_url: String,
|
||||
git_url: String,
|
||||
submodule_git_url: Option<String>,
|
||||
content: String
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct GitLabFailedJSON {
|
||||
errors: Option<String>,
|
||||
message: String,
|
||||
url: String
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
async fn paste_render(data: Data<Template>, paste: Query<Paste>) -> impl Responder {
|
||||
let my_data = data.get_ref();
|
||||
let mut context = Context::new();
|
||||
let gitlab_token = env::var("GITLAB_TOKEN").unwrap_or("".to_string());
|
||||
let base_url = env::var("BASE_URL").unwrap_or("https://gitlab.com".to_string());
|
||||
let gitlab_token = env::var("GITEA_TOKEN").unwrap_or("".to_string());
|
||||
let base_url = env::var("BASE_URL").unwrap_or("https://gitea.com".to_string());
|
||||
let client = Client::new();
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("PRIVATE-TOKEN", gitlab_token.parse().unwrap());
|
||||
headers.insert("Authorization", gitlab_token.parse().unwrap());
|
||||
let paste_content: String;
|
||||
if paste.paste_id.is_some() {
|
||||
let response = client.get(format!("{}/repository/files/paste%2F{}.md?ref=master", base_url, paste.paste_id.as_ref().unwrap())).headers(headers).send().await.unwrap();
|
||||
let response = client.get(format!("{}/contents/{}?ref=master", base_url, paste.paste_id.as_ref().unwrap())).headers(headers).send().await.unwrap();
|
||||
let response_code = response.status().as_str().to_string();
|
||||
let response_json = response.text().await.unwrap();
|
||||
if response_code != "200" {
|
||||
let resp_struct: GitLabFailedJSON = serde_json::from_str(&response_json).unwrap();
|
||||
if resp_struct.message == "404 Project Not Found" {
|
||||
if resp_struct.message == "The target couldn't be found." {
|
||||
context.insert("md", "true");
|
||||
paste_content = "Project ID Mismatch/GitLab Token Missing".to_string();
|
||||
paste_content = "Project ID Mismatch/Gitea Token Missing".to_string();
|
||||
}
|
||||
else {
|
||||
context.insert("md", "true");
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
@import url("https://fonts.googleapis.com/css?family=IBM Plex Sans");
|
||||
@import url("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/atom-one-dark.min.css");
|
||||
@import url("https://cdnjs.cloudflare.com/ajax/libs/hack-font/3.3.0/web/hack.css");
|
||||
@import url("https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css");
|
||||
|
||||
body {
|
||||
font-family: "IBM Plex Sans";
|
||||
}
|
||||
|
||||
pre {
|
||||
overflow-x: auto;
|
||||
white-space: pre-wrap;
|
||||
white-space: -moz-pre-wrap;
|
||||
white-space: -pre-wrap;
|
||||
white-space: -o-pre-wrap;
|
||||
word-wrap: break-word;
|
||||
code[class*="language-*"] {
|
||||
font-family: "Fira Code" !important;
|
||||
}
|
||||
|
||||
.hljs {
|
||||
font-family: "Hack" !important;
|
||||
.mdpaste {
|
||||
white-space: normal !important;
|
||||
word-break: break-word !important;
|
||||
font-family: "Lunasima" !important;
|
||||
font-size: 14 !important;
|
||||
color: "white" !important;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
! tailwindcss v3.3.2 | MIT License | https://tailwindcss.com
|
||||
! tailwindcss v3.2.4 | MIT License | https://tailwindcss.com
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -31,7 +31,6 @@
|
|||
3. Use a more readable tab size.
|
||||
4. Use the user's configured `sans` font-family by default.
|
||||
5. Use the user's configured `sans` font-feature-settings by default.
|
||||
6. Use the user's configured `sans` font-variation-settings by default.
|
||||
*/
|
||||
|
||||
html {
|
||||
|
@ -48,8 +47,6 @@ html {
|
|||
/* 4 */
|
||||
font-feature-settings: normal;
|
||||
/* 5 */
|
||||
font-variation-settings: normal;
|
||||
/* 6 */
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -436,9 +433,6 @@ video {
|
|||
--tw-pan-y: ;
|
||||
--tw-pinch-zoom: ;
|
||||
--tw-scroll-snap-strictness: proximity;
|
||||
--tw-gradient-from-position: ;
|
||||
--tw-gradient-via-position: ;
|
||||
--tw-gradient-to-position: ;
|
||||
--tw-ordinal: ;
|
||||
--tw-slashed-zero: ;
|
||||
--tw-numeric-figure: ;
|
||||
|
@ -486,9 +480,6 @@ video {
|
|||
--tw-pan-y: ;
|
||||
--tw-pinch-zoom: ;
|
||||
--tw-scroll-snap-strictness: proximity;
|
||||
--tw-gradient-from-position: ;
|
||||
--tw-gradient-via-position: ;
|
||||
--tw-gradient-to-position: ;
|
||||
--tw-ordinal: ;
|
||||
--tw-slashed-zero: ;
|
||||
--tw-numeric-figure: ;
|
||||
|
@ -590,14 +581,14 @@ video {
|
|||
width: 2.5rem;
|
||||
}
|
||||
|
||||
.w-10\/12 {
|
||||
width: 83.333333%;
|
||||
}
|
||||
|
||||
.w-screen {
|
||||
width: 100vw;
|
||||
}
|
||||
|
||||
.w-10\/12 {
|
||||
width: 83.333333%;
|
||||
}
|
||||
|
||||
.border-collapse {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@
|
|||
<h2 class="text-3xl font-bold text-gray-300">Obsolute Paste</h2>
|
||||
{% block content %}
|
||||
{% if md %}
|
||||
<link href='https://fonts.googleapis.com/css?family=Lunasima' rel='stylesheet'>
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<div class="w-10/12 text-gray-100 border border-solid border-emerald-200 rounded bg-zinc-800 p-2" id="pastecontent"></div>
|
||||
<div class="w-10/12 text-gray-100 border border-solid border-emerald-200 rounded bg-zinc-800 p-2 mdpaste" id="pastecontent"></div>
|
||||
<script>
|
||||
document.getElementById('pastecontent').innerHTML = marked.parse(`{{paste_content}}`);
|
||||
</script>
|
||||
|
@ -24,9 +25,14 @@
|
|||
document.addEventListener("DOMContentLoaded", (event) => {
|
||||
const elem = document.getElementById("pastecontent");
|
||||
hljs.highlightElement(elem);
|
||||
Prism.highlightElement(elem);
|
||||
});
|
||||
</script>
|
||||
<pre class="w-10/12 text-gray-100 border border-solid border-emerald-200 rounded bg-zinc-800 p-2" id="pastecontent">{{paste_content}}</pre>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
|
||||
<link href='https://fonts.googleapis.com/css?family=Fira Code' rel='stylesheet'>
|
||||
<pre class="w-10/12 text-gray-100 border border-solid border-emerald-200 rounded bg-zinc-800 p-2"><code id="pastecontent">{{paste_content}}</code></pre>
|
||||
{% endif %}
|
||||
{% endblock content %}
|
||||
</div>
|
||||
|
@ -66,4 +72,4 @@
|
|||
</script>
|
||||
<!-- End Matomo Code -->
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue