Skip to content

Commit ba784da

Browse files
committed
Merge branch 'pr/95'
2 parents 66f6e0e + 68f4081 commit ba784da

File tree

15 files changed

+198
-53
lines changed

15 files changed

+198
-53
lines changed

.github/workflows/gh-release.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: GitHub Release
2+
3+
on:
4+
push:
5+
tags:
6+
- v[0-9]+.[0-9]+.[0-9]+*
7+
8+
jobs:
9+
release:
10+
name: Publish to Github Releases
11+
outputs:
12+
rc: ${{ steps.check-tag.outputs.rc }}
13+
strategy:
14+
matrix:
15+
include:
16+
- target: aarch64-unknown-linux-musl
17+
os: ubuntu-latest
18+
use-cross: true
19+
cargo-flags: ""
20+
- target: aarch64-apple-darwin
21+
os: macos-latest
22+
use-cross: true
23+
cargo-flags: ""
24+
- target: aarch64-pc-windows-msvc
25+
os: windows-latest
26+
use-cross: true
27+
cargo-flags: "--no-default-features"
28+
- target: x86_64-apple-darwin
29+
os: macos-latest
30+
cargo-flags: ""
31+
- target: x86_64-pc-windows-msvc
32+
os: windows-latest
33+
cargo-flags: ""
34+
- target: x86_64-unknown-linux-musl
35+
os: ubuntu-latest
36+
use-cross: true
37+
cargo-flags: ""
38+
- target: i686-unknown-linux-musl
39+
os: ubuntu-latest
40+
use-cross: true
41+
cargo-flags: ""
42+
- target: i686-pc-windows-msvc
43+
os: windows-latest
44+
use-cross: true
45+
cargo-flags: ""
46+
- target: armv7-unknown-linux-musleabihf
47+
os: ubuntu-latest
48+
use-cross: true
49+
cargo-flags: ""
50+
- target: arm-unknown-linux-musleabihf
51+
os: ubuntu-latest
52+
use-cross: true
53+
cargo-flags: ""
54+
- target: mips-unknown-linux-musl
55+
os: ubuntu-latest
56+
use-cross: true
57+
cargo-flags: "--no-default-features"
58+
- target: mipsel-unknown-linux-musl
59+
os: ubuntu-latest
60+
use-cross: true
61+
cargo-flags: "--no-default-features"
62+
- target: mips64-unknown-linux-gnuabi64
63+
os: ubuntu-latest
64+
use-cross: true
65+
cargo-flags: "--no-default-features"
66+
- target: mips64el-unknown-linux-gnuabi64
67+
os: ubuntu-latest
68+
use-cross: true
69+
cargo-flags: "--no-default-features"
70+
runs-on: ${{matrix.os}}
71+
72+
steps:
73+
- uses: actions/checkout@v2
74+
75+
- name: Check Tag
76+
id: check-tag
77+
shell: bash
78+
run: |
79+
tag=${GITHUB_REF##*/}
80+
echo "::set-output name=version::$tag"
81+
if [[ "$tag" =~ [0-9]+.[0-9]+.[0-9]+$ ]]; then
82+
echo "::set-output name=rc::false"
83+
else
84+
echo "::set-output name=rc::true"
85+
fi
86+
87+
88+
- name: Install Rust Toolchain Components
89+
uses: actions-rs/toolchain@v1
90+
with:
91+
override: true
92+
target: ${{ matrix.target }}
93+
toolchain: stable
94+
profile: minimal # minimal component installation (ie, no documentation)
95+
96+
- name: Show Version Information (Rust, cargo, GCC)
97+
shell: bash
98+
run: |
99+
gcc --version || true
100+
rustup -V
101+
rustup toolchain list
102+
rustup default
103+
cargo -V
104+
rustc -V
105+
106+
- name: Build
107+
uses: actions-rs/cargo@v1
108+
with:
109+
use-cross: ${{ matrix.use-cross }}
110+
command: build
111+
args: --locked --release --target=${{ matrix.target }} ${{ matrix.cargo-flags }}
112+
113+
- name: Build Archive
114+
shell: bash
115+
id: package
116+
env:
117+
target: ${{ matrix.target }}
118+
version: ${{ steps.check-tag.outputs.version }}
119+
run: |
120+
set -euxo pipefail
121+
122+
bin=${GITHUB_REPOSITORY##*/}
123+
src=`pwd`
124+
dist=$src/dist
125+
name=$bin-$version-$target
126+
executable=target/$target/release/$bin
127+
128+
if [[ "$RUNNER_OS" == "Windows" ]]; then
129+
executable=$executable.exe
130+
fi
131+
132+
mkdir $dist
133+
cp $executable $dist
134+
cd $dist
135+
136+
if [[ "$RUNNER_OS" == "Windows" ]]; then
137+
archive=$dist/$name.zip
138+
7z a $archive *
139+
echo "::set-output name=archive::`pwd -W`/$name.zip"
140+
else
141+
archive=$dist/$name.tar.gz
142+
tar czf $archive *
143+
echo "::set-output name=archive::$archive"
144+
fi
145+
146+
- name: Publish Archive
147+
uses: softprops/[email protected]
148+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
149+
with:
150+
draft: false
151+
files: ${{ steps.package.outputs.archive }}
152+
prerelease: ${{ steps.check-tag.outputs.rc == 'true' }}
153+
env:
154+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RUN \
88
DEBIAN_FRONTEND=noninteractive \
99
apt-get update &&\
1010
apt-get -y install ca-certificates tzdata &&\
11+
CARGO_NET_GIT_FETCH_WITH_CLI=true \
1112
cargo build --release
1213

1314
# https://hub.docker.com/r/bitnami/minideb
@@ -25,12 +26,12 @@ COPY --from=build \
2526
/etc/ssl/certs/ca-certificates.crt \
2627
/etc/ssl/certs/ca-certificates.crt
2728

28-
# copy built exacutable
29+
# copy built executable
2930
COPY --from=build \
3031
/app/target/release/microbin \
3132
/usr/bin/microbin
3233

3334
# Expose webport used for the webserver to the docker runtime
3435
EXPOSE 8080
3536

36-
ENTRYPOINT ["microbin"]
37+
ENTRYPOINT ["microbin"]

README.MD renamed to README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ And run with your custom configuration:
1919

2020
Or get the Docker image from [Dockerhub: danielszabo99/microbin](https://hub.docker.com/r/danielszabo99/microbin)
2121

22-
On our website [microbin.eu](microbin.eu) you will find the following:
22+
On our website [microbin.eu](https://microbin.eu) you will find the following:
2323

2424
- [Screenshots](https://microbin.eu/screenshots/)
2525
- [Quickstart Guide](https://microbin.eu/quickstart/)
2626
- [Documentation](https://microbin.eu/documentation/)
27-
- [Donations and Sponsorhip](https://microbin.eu/donate/)
27+
- [Donations and Sponsorships](https://microbin.eu/donate/)
2828
- [Community](https://microbin.eu/community/)
2929

3030
### Features
@@ -67,4 +67,4 @@ You can use MicroBin
6767

6868
MicroBin and MicroBin.eu are available under the BSD 3-Clause License.
6969

70-
© Dániel Szabó 2022
70+
© Dániel Szabó 2022

src/endpoints/create.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub async fn create(
122122
while let Some(chunk) = field.try_next().await? {
123123
content.push_str(std::str::from_utf8(&chunk).unwrap().to_string().as_str());
124124
}
125-
if content.len() > 0 {
125+
if !content.is_empty() {
126126
new_pasta.content = content;
127127

128128
new_pasta.pasta_type = if is_valid_url(new_pasta.content.as_str()) {
@@ -152,7 +152,7 @@ pub async fn create(
152152
None => continue,
153153
};
154154

155-
let mut file = match PastaFile::from_unsanitized(&path) {
155+
let mut file = match PastaFile::from_unsanitized(path) {
156156
Ok(f) => f,
157157
Err(e) => {
158158
warn!("Unsafe file name: {e:?}");

src/endpoints/edit.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pub async fn get_edit(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
2222
let mut pastas = data.pastas.lock().unwrap();
2323

2424
let id = if ARGS.hash_ids {
25-
hashid_to_u64(&*id).unwrap_or(0)
25+
hashid_to_u64(&id).unwrap_or(0)
2626
} else {
27-
to_u64(&*id.into_inner()).unwrap_or(0)
27+
to_u64(&id.into_inner()).unwrap_or(0)
2828
};
2929

3030
remove_expired(&mut pastas);
@@ -36,14 +36,9 @@ pub async fn get_edit(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
3636
.append_header(("Location", format!("{}/", ARGS.public_path)))
3737
.finish();
3838
}
39-
return HttpResponse::Ok().content_type("text/html").body(
40-
EditTemplate {
41-
pasta: &pasta,
42-
args: &ARGS,
43-
}
44-
.render()
45-
.unwrap(),
46-
);
39+
return HttpResponse::Ok()
40+
.content_type("text/html")
41+
.body(EditTemplate { pasta, args: &ARGS }.render().unwrap());
4742
}
4843
}
4944

@@ -65,9 +60,9 @@ pub async fn post_edit(
6560
}
6661

6762
let id = if ARGS.hash_ids {
68-
hashid_to_u64(&*id).unwrap_or(0)
63+
hashid_to_u64(&id).unwrap_or(0)
6964
} else {
70-
to_u64(&*id.into_inner()).unwrap_or(0)
65+
to_u64(&id.into_inner()).unwrap_or(0)
7166
};
7267

7368
let mut pastas = data.pastas.lock().unwrap();
@@ -77,20 +72,17 @@ pub async fn post_edit(
7772
let mut new_content = String::from("");
7873

7974
while let Some(mut field) = payload.try_next().await? {
80-
match field.name() {
81-
"content" => {
82-
while let Some(chunk) = field.try_next().await? {
83-
new_content = std::str::from_utf8(&chunk).unwrap().to_string();
84-
}
75+
if field.name() == "content" {
76+
while let Some(chunk) = field.try_next().await? {
77+
new_content = std::str::from_utf8(&chunk).unwrap().to_string();
8578
}
86-
_ => {}
8779
}
8880
}
8981

9082
for (i, pasta) in pastas.iter().enumerate() {
9183
if pasta.id == id {
9284
if pasta.editable {
93-
pastas[i].content.replace_range(.., &*new_content);
85+
pastas[i].content.replace_range(.., &new_content);
9486
save_to_file(&pastas);
9587

9688
return Ok(HttpResponse::Found()

src/endpoints/info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct Info<'a> {
1717
#[get("/info")]
1818
pub async fn info(data: web::Data<AppState>) -> HttpResponse {
1919
// get access to the pasta collection
20-
let mut pastas = data.pastas.lock().unwrap();
20+
let pastas = data.pastas.lock().unwrap();
2121

2222
// todo status report more sophisticated
2323
let mut status = "OK";

src/endpoints/pasta.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::util::animalnumbers::to_u64;
66
use crate::util::hashids::to_u64 as hashid_to_u64;
77
use crate::util::misc::remove_expired;
88
use crate::AppState;
9-
use actix_web::rt::time;
9+
1010
use actix_web::{get, web, HttpResponse};
1111
use askama::Template;
1212
use std::time::{SystemTime, UNIX_EPOCH};
@@ -24,9 +24,9 @@ pub async fn getpasta(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
2424
let mut pastas = data.pastas.lock().unwrap();
2525

2626
let id = if ARGS.hash_ids {
27-
hashid_to_u64(&*id).unwrap_or(0)
27+
hashid_to_u64(&id).unwrap_or(0)
2828
} else {
29-
to_u64(&*id.into_inner()).unwrap_or(0)
29+
to_u64(&id.into_inner()).unwrap_or(0)
3030
};
3131

3232
// remove expired pastas (including this one if needed)
@@ -45,7 +45,7 @@ pub async fn getpasta(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
4545

4646
if found {
4747
// increment read count
48-
pastas[index].read_count = pastas[index].read_count + 1;
48+
pastas[index].read_count += 1;
4949

5050
// save the updated read count
5151
save_to_file(&pastas);
@@ -88,9 +88,9 @@ pub async fn redirecturl(data: web::Data<AppState>, id: web::Path<String>) -> Ht
8888
let mut pastas = data.pastas.lock().unwrap();
8989

9090
let id = if ARGS.hash_ids {
91-
hashid_to_u64(&*id).unwrap_or(0)
91+
hashid_to_u64(&id).unwrap_or(0)
9292
} else {
93-
to_u64(&*id.into_inner()).unwrap_or(0)
93+
to_u64(&id.into_inner()).unwrap_or(0)
9494
};
9595

9696
// remove expired pastas (including this one if needed)
@@ -110,7 +110,7 @@ pub async fn redirecturl(data: web::Data<AppState>, id: web::Path<String>) -> Ht
110110

111111
if found {
112112
// increment read count
113-
pastas[index].read_count = pastas[index].read_count + 1;
113+
pastas[index].read_count += 1;
114114

115115
// save the updated read count
116116
save_to_file(&pastas);
@@ -155,9 +155,9 @@ pub async fn getrawpasta(data: web::Data<AppState>, id: web::Path<String>) -> St
155155
let mut pastas = data.pastas.lock().unwrap();
156156

157157
let id = if ARGS.hash_ids {
158-
hashid_to_u64(&*id).unwrap_or(0)
158+
hashid_to_u64(&id).unwrap_or(0)
159159
} else {
160-
to_u64(&*id.into_inner()).unwrap_or(0)
160+
to_u64(&id.into_inner()).unwrap_or(0)
161161
};
162162

163163
// remove expired pastas (including this one if needed)
@@ -176,7 +176,7 @@ pub async fn getrawpasta(data: web::Data<AppState>, id: web::Path<String>) -> St
176176

177177
if found {
178178
// increment read count
179-
pastas[index].read_count = pastas[index].read_count + 1;
179+
pastas[index].read_count += 1;
180180

181181
// get current unix time in seconds
182182
let timenow: i64 = match SystemTime::now().duration_since(UNIX_EPOCH) {

src/endpoints/qr.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ use crate::util::misc::{self, remove_expired};
77
use crate::AppState;
88
use actix_web::{get, web, HttpResponse};
99
use askama::Template;
10-
use qrcode_generator::QrCodeEcc;
11-
use std::time::{SystemTime, UNIX_EPOCH};
1210

1311
#[derive(Template)]
1412
#[template(path = "qr.html", escape = "none")]

src/endpoints/remove.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub async fn remove(data: web::Data<AppState>, id: web::Path<String>) -> HttpRes
2121
let mut pastas = data.pastas.lock().unwrap();
2222

2323
let id = if ARGS.hash_ids {
24-
hashid_to_u64(&*id).unwrap_or(0)
24+
hashid_to_u64(&id).unwrap_or(0)
2525
} else {
26-
to_u64(&*id.into_inner()).unwrap_or(0)
26+
to_u64(&id.into_inner()).unwrap_or(0)
2727
};
2828

2929
for (i, pasta) in pastas.iter().enumerate() {

src/endpoints/static_resources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
1+
use actix_web::{web, HttpResponse, Responder};
22
use mime_guess::from_path;
33
use rust_embed::RustEmbed;
44

0 commit comments

Comments
 (0)