Add flake
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
asonix 2023-03-09 21:30:31 -06:00
parent 0123d93458
commit 09493c7f91
7 changed files with 581 additions and 407 deletions

3
.gitignore vendored
View file

@ -1,2 +1,5 @@
/target
/docker/dev/volumes
/.envrc
/.direnv
/result

855
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -29,7 +29,7 @@ once_cell = "1.4"
opentelemetry = { version = "0.18", features = ["rt-tokio"] }
opentelemetry-otlp = "0.11"
serde = { version = "1.0", features = ["derive"] }
serde_qs = { version = "0.10", features = ["actix4"] }
serde_qs = { version = "0.12", features = ["actix4"] }
thiserror = "1.0"
tracing = "0.1"
tracing-error = "0.2"
@ -44,7 +44,7 @@ tracing-subscriber = { version = "0.3", features = [
url = "2.1"
[dependencies.tracing-actix-web]
version = "0.6.1"
version = "0.7.2"
default-features = false
features = ["emit_event_on_error", "opentelemetry_0_18"]
@ -56,4 +56,4 @@ features = ["emit_event_on_error", "opentelemetry_0_18"]
[build-dependencies]
anyhow = "1.0"
dotenv = "0.15.0"
ructe = { version = "0.15.0", features = ["sass", "mime03"] }
ructe = { version = "0.16.1", features = ["sass", "mime03"] }

43
flake.lock Normal file
View file

@ -0,0 +1,43 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1676283394,
"narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1678293141,
"narHash": "sha256-lLlQHaR0y+q6nd6kfpydPTGHhl1rS9nU9OQmztzKOYs=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c90c4025bb6e0c4eaf438128a3b2640314b1c58d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

34
flake.nix Normal file
View file

@ -0,0 +1,34 @@
{
description = "pict-rs-proxy";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
packages = rec {
pict-rs-proxy = pkgs.callPackage ./pict-rs-proxy.nix { };
default = pict-rs-proxy;
};
apps = rec {
dev = flake-utils.lib.mkApp { drv = self.packages.${system}.pict-rs-proxy; };
default = dev;
};
devShell = with pkgs; mkShell {
nativeBuildInputs = [ cargo cargo-outdated cargo-zigbuild clippy gcc protobuf rust-analyzer rustc rustfmt ];
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
});
}

27
pict-rs-proxy.nix Normal file
View file

@ -0,0 +1,27 @@
{ lib
, makeWrapper
, nixosTests
, protobuf
, rustPlatform
, stdenv
}:
rustPlatform.buildRustPackage {
pname = "pict-rs-proxy";
version = "0.4.0-beta.1";
src = ./.;
cargoSha256 = "SKj8drv60RcdpWNGaU+nSiFlTAU+WT+byg5EtN7Efk8=";
PROTOC = "${protobuf}/bin/protoc";
PROTOC_INCLUDE = "${protobuf}/include";
nativeBuildInputs = [ ];
passthru.tests = { inherit (nixosTests) pict-rs-proxy; };
meta = with lib; {
description = "A simple image hosting service";
homepage = "https://git.asonix.dog/asonix/pict-rs-proxy";
license = with licenses; [ agpl3Plus ];
};
}

View file

@ -379,7 +379,7 @@ impl ResponseError for Error {
fn error_response(&self) -> HttpResponse {
match render(HttpResponse::build(self.status_code()), |cursor| {
self::templates::error(cursor, &self.kind.to_string())
self::templates::error_html(cursor, &self.kind.to_string())
}) {
Ok(res) => res,
Err(_) => HttpResponse::build(self.status_code())
@ -413,7 +413,7 @@ enum ErrorKind {
#[tracing::instrument(name = "Upload Page")]
async fn index() -> Result<HttpResponse, Error> {
render(HttpResponse::Ok(), |cursor| {
self::templates::index(cursor, "/upload", "images[]")
self::templates::index_html(cursor, "/upload", "images[]")
})
}
@ -526,12 +526,12 @@ async fn list_uploads(
}
return render(HttpResponse::Ok(), |cursor| {
self::templates::uploads(cursor)
self::templates::uploads_html(cursor)
});
}
render(HttpResponse::Ok(), |cursor| {
self::templates::finished_uploads(cursor, results)
self::templates::finished_uploads_html(cursor, results)
})
}
@ -592,7 +592,7 @@ async fn thumbs(
};
render(HttpResponse::Ok(), |cursor| {
self::templates::thumbnails(cursor, image, THUMBNAIL_SIZES)
self::templates::thumbnails_html(cursor, image, THUMBNAIL_SIZES)
})
}
@ -647,7 +647,7 @@ async fn view_original(
};
render(HttpResponse::Ok(), |cursor| {
self::templates::view(cursor, image, None, THUMBNAIL_SIZES.last())
self::templates::view_html(cursor, image, None, THUMBNAIL_SIZES.last())
})
}
@ -678,7 +678,7 @@ async fn view(
};
render(HttpResponse::Ok(), |cursor| {
self::templates::view(cursor, image, Some(size), THUMBNAIL_SIZES.last())
self::templates::view_html(cursor, image, Some(size), THUMBNAIL_SIZES.last())
})
}
@ -766,13 +766,13 @@ async fn delete(
client.delete(url).send().await?;
render(HttpResponse::Ok(), |cursor| {
self::templates::deleted(cursor, &file)
self::templates::deleted_html(cursor, &file)
})
} else {
let details: Details = res.json().await?;
render(HttpResponse::Ok(), move |cursor| {
self::templates::confirm_delete(
self::templates::confirm_delete_html(
cursor,
&Image {
file,
@ -793,7 +793,7 @@ fn to_404() -> HttpResponse {
#[tracing::instrument(name = "Not Found")]
async fn not_found() -> Result<HttpResponse, Error> {
render(HttpResponse::NotFound(), |cursor| {
self::templates::not_found(cursor)
self::templates::not_found_html(cursor)
})
}