├── migrations
├── .keep
├── 2022-10-23-160940_create_users_table
│ ├── down.sql
│ └── up.sql
├── 2022-10-23-193539_create_api_tokens_table
│ ├── down.sql
│ └── up.sql
├── 2022-10-27-193452_create_plugins_table
│ ├── down.sql
│ └── up.sql
├── 2022-10-27-204919_create_versions_table
│ ├── down.sql
│ └── up.sql
└── 00000000000000_diesel_initial_setup
│ ├── down.sql
│ └── up.sql
├── .dockerignore
├── volts-core
├── src
│ ├── db
│ │ ├── api.rs
│ │ ├── mod.rs
│ │ ├── schema.rs
│ │ └── models.rs
│ ├── util
│ │ ├── mod.rs
│ │ └── rfc3339.rs
│ └── lib.rs
└── Cargo.toml
├── volts-cli
├── src
│ ├── bin
│ │ └── volts.rs
│ ├── lib.rs
│ └── commands.rs
└── Cargo.toml
├── nginx
├── volt.png
├── default.conf
├── index.html
├── nginx.conf
└── mime.types
├── .gitignore
├── volts-front
├── src
│ ├── components
│ │ ├── mod.rs
│ │ ├── navbar.rs
│ │ ├── token.rs
│ │ └── plugin.rs
│ └── lib.rs
├── Trunk.toml
├── index.html
├── Cargo.toml
├── dist
│ └── index.html
├── tailwind.config.js
└── assets
│ └── tailwind.css
├── volts-back
├── src
│ ├── bin
│ │ └── server.rs
│ ├── lib.rs
│ ├── util.rs
│ ├── token.rs
│ ├── github.rs
│ ├── state.rs
│ ├── router.rs
│ ├── db.rs
│ └── plugin.rs
└── Cargo.toml
├── diesel.toml
├── Cargo.toml
├── fly.toml
└── Dockerfile
/migrations/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.dockerignore:
--------------------------------------------------------------------------------
1 | /target
2 | fly.toml
--------------------------------------------------------------------------------
/volts-core/src/db/api.rs:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/volts-core/src/util/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod rfc3339;
2 |
--------------------------------------------------------------------------------
/volts-cli/src/bin/volts.rs:
--------------------------------------------------------------------------------
1 | pub fn main() {
2 | volts::cli();
3 | }
4 |
--------------------------------------------------------------------------------
/nginx/volt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lapce/lapce-volts/HEAD/nginx/volt.png
--------------------------------------------------------------------------------
/volts-core/src/db/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod api;
2 | pub mod models;
3 | pub mod schema;
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | .env
3 | .DS_Store
4 |
5 | volts-front/dist
6 |
7 | .vscode
8 | .lapce
--------------------------------------------------------------------------------
/volts-front/src/components/mod.rs:
--------------------------------------------------------------------------------
1 | pub(crate) mod navbar;
2 | pub(crate) mod plugin;
3 | pub(crate) mod token;
4 |
--------------------------------------------------------------------------------
/volts-back/src/bin/server.rs:
--------------------------------------------------------------------------------
1 | #[tokio::main]
2 | async fn main() {
3 | volts_back::start_server().await;
4 | }
5 |
--------------------------------------------------------------------------------
/migrations/2022-10-23-160940_create_users_table/down.sql:
--------------------------------------------------------------------------------
1 | -- This file should undo anything in `up.sql`
2 | drop table users;
--------------------------------------------------------------------------------
/migrations/2022-10-23-193539_create_api_tokens_table/down.sql:
--------------------------------------------------------------------------------
1 | -- This file should undo anything in `up.sql`
2 | drop table api_tokens;
--------------------------------------------------------------------------------
/migrations/2022-10-27-193452_create_plugins_table/down.sql:
--------------------------------------------------------------------------------
1 | -- This file should undo anything in `up.sql`
2 | drop table plugins;
3 |
--------------------------------------------------------------------------------
/migrations/2022-10-27-204919_create_versions_table/down.sql:
--------------------------------------------------------------------------------
1 | -- This file should undo anything in `up.sql`
2 | drop table versions;
3 |
--------------------------------------------------------------------------------
/volts-front/Trunk.toml:
--------------------------------------------------------------------------------
1 | [watch]
2 | watch = ["src/"]
3 |
4 | [serve]
5 | address = "127.0.0.1"
6 | port = 3000
7 | open = false
8 |
9 | [[proxy]]
10 | rewrite = "/api/"
11 | backend = "http://localhost:8080/api"
12 |
--------------------------------------------------------------------------------
/diesel.toml:
--------------------------------------------------------------------------------
1 | # For documentation on how to configure this file,
2 | # see https://diesel.rs/guides/configuring-diesel-cli
3 |
4 | [print_schema]
5 | file = "src/db/schema.rs"
6 |
7 | [migrations_directory]
8 | dir = "migrations"
9 |
--------------------------------------------------------------------------------
/migrations/00000000000000_diesel_initial_setup/down.sql:
--------------------------------------------------------------------------------
1 | -- This file was automatically created by Diesel to setup helper functions
2 | -- and other internal bookkeeping. This file is safe to edit, any future
3 | -- changes will be added to existing projects as new migrations.
4 |
5 | DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
6 | DROP FUNCTION IF EXISTS diesel_set_updated_at();
7 |
--------------------------------------------------------------------------------
/migrations/2022-10-23-160940_create_users_table/up.sql:
--------------------------------------------------------------------------------
1 | -- Your SQL goes here
2 | create table users (
3 | id SERIAL PRIMARY KEY,
4 | gh_access_token VARCHAR NOT NULL,
5 | gh_login VARCHAR NOT NULL,
6 | gh_id INTEGER NOT NULL
7 | );
8 |
9 | CREATE UNIQUE INDEX users_gh_id ON users (gh_id);
10 | CREATE INDEX users_gh_login ON users (gh_login);
11 |
--------------------------------------------------------------------------------
/volts-core/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "volts-core"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 |
8 | [dependencies]
9 | chrono = "0.4.22"
10 | diesel = { version = "2.0.2", features = ["postgres", "chrono"] }
11 | anyhow = "1.0.66"
12 | url = "2.3.1"
13 | serde = { version = "1.0", features = ["derive"] }
14 |
--------------------------------------------------------------------------------
/volts-front/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Yew App
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/nginx/default.conf:
--------------------------------------------------------------------------------
1 | server {
2 | listen 3000;
3 | server_name _;
4 |
5 | location / {
6 | root /app/static;
7 | try_files $uri /index.html;
8 | }
9 |
10 | location /static/ {
11 | root /app/;
12 | add_header Cache-Control "public, max-age=86400";
13 | }
14 |
15 | location /api {
16 | proxy_pass http://127.0.0.1:8080;
17 | }
18 |
19 | client_max_body_size 100M;
20 | }
21 |
--------------------------------------------------------------------------------
/migrations/2022-10-23-193539_create_api_tokens_table/up.sql:
--------------------------------------------------------------------------------
1 | -- Your SQL goes here
2 | CREATE TABLE "public"."api_tokens" (
3 | "id" SERIAL PRIMARY KEY,
4 | "user_id" INTEGER NOT NULL,
5 | "token" bytea NOT NULL,
6 | "name" varchar NOT NULL,
7 | "created_at" timestamp NOT NULL DEFAULT now(),
8 | "last_used_at" timestamp,
9 | "revoked" bool NOT NULL DEFAULT false,
10 | CONSTRAINT "api_tokens_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id")
11 | );
12 |
13 | CREATE UNIQUE INDEX api_tokens_token ON api_tokens (token)
--------------------------------------------------------------------------------
/volts-back/src/lib.rs:
--------------------------------------------------------------------------------
1 | use std::net::SocketAddr;
2 |
3 | pub(crate) mod db;
4 | pub mod github;
5 | pub(crate) mod plugin;
6 | pub mod router;
7 | pub mod state;
8 | pub mod token;
9 | pub mod util;
10 |
11 | #[macro_use]
12 | extern crate diesel;
13 |
14 | pub async fn start_server() {
15 | dotenvy::dotenv().ok();
16 | let router = crate::router::build_router();
17 | let addr = SocketAddr::from(([0, 0, 0, 0], 8080));
18 | axum::Server::bind(&addr)
19 | .serve(router.into_make_service())
20 | .await
21 | .unwrap();
22 | }
23 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "lapce-volts"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | [dependencies]
7 | tokio = { version = "1.21.2", features = ["full"] }
8 | volts-front = { path = "./volts-front" }
9 | volts-back = { path = "./volts-back" }
10 | volts = { path = "./volts-cli" }
11 |
12 | [[bin]]
13 | name = "volts-server"
14 | path = "volts-back/src/bin/server.rs"
15 |
16 | [[bin]]
17 | name = "volts"
18 | path = "volts-cli/src/bin/volts.rs"
19 |
20 | [workspace]
21 | members = [
22 | "volts-core",
23 | "volts-front",
24 | "volts-back",
25 | "volts-cli",
26 | ]
--------------------------------------------------------------------------------
/volts-cli/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "volts"
3 | description = "Cli tool for publishing and managing Lapce plugins"
4 | license = "Apache-2.0"
5 | version = "0.2.1"
6 | edition = "2021"
7 |
8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9 |
10 | [dependencies]
11 | reqwest = { version = "0.11.12", features = ["blocking"] }
12 | lapce-rpc = "0.2.1"
13 | tempfile = "3.3.0"
14 | tar = "0.4.38"
15 | toml_edit = { version = "0.14.4", features = ["easy"] }
16 | serde = { version = "1.0", features = ["derive"] }
17 | clap = { version = "4.0", features = ["derive"] }
18 | keyring = { version = "1.2.0" }
19 | zstd = "0.11"
--------------------------------------------------------------------------------
/migrations/2022-10-27-204919_create_versions_table/up.sql:
--------------------------------------------------------------------------------
1 | -- Your SQL goes here
2 | create table versions (
3 | id SERIAL PRIMARY KEY,
4 | plugin_id INTEGER NOT NULL,
5 | updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
6 | created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
7 | num VARCHAR NOT NULL,
8 | downloads INTEGER NOT NULL DEFAULT 0,
9 | yanked bool NOT NULL DEFAULT false,
10 | CONSTRAINT "versions_plugin_id_fkey" FOREIGN KEY ("plugin_id") REFERENCES "public"."plugins"("id")
11 | );
12 |
13 | CREATE UNIQUE INDEX versions_plugin_id_num ON versions (plugin_id, num);
14 |
--------------------------------------------------------------------------------
/volts-front/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "volts-front"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 |
8 | [dependencies]
9 | pulldown-cmark = "0.9.2"
10 | url = "2.3.1"
11 | gloo-net = "0.2.4"
12 | web-sys = { version = "0.3.60", features = ["HtmlImageElement"] }
13 | wasm-bindgen = "0.2.83"
14 | wasm-bindgen-futures = "0.4.33"
15 | gloo-timers = { version = "0.2.3", features = ["futures"] }
16 | console_error_panic_hook = "0.1.7"
17 | sycamore-router = "0.8.0"
18 | sycamore = { version = "0.8.2", features = ["suspense"] }
19 | volts-core = { path = "../volts-core" }
20 |
21 | [lib]
22 | crate-type = ["cdylib", "rlib"]
23 |
--------------------------------------------------------------------------------
/nginx/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Lapce Plugins
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/fly.toml:
--------------------------------------------------------------------------------
1 | # fly.toml file generated for volts on 2022-10-26T20:03:53+01:00
2 |
3 | app = "volts"
4 | kill_signal = "SIGINT"
5 | kill_timeout = 5
6 | processes = []
7 |
8 | [env]
9 |
10 | [experimental]
11 | allowed_public_ports = []
12 | auto_rollback = true
13 |
14 | [[services]]
15 | http_checks = []
16 | internal_port = 3000
17 | processes = ["app"]
18 | protocol = "tcp"
19 | script_checks = []
20 |
21 | [services.concurrency]
22 | hard_limit = 100
23 | soft_limit = 25
24 | type = "connections"
25 |
26 | [[services.ports]]
27 | force_https = false
28 | handlers = ["http"]
29 | port = 80
30 |
31 | [[services.ports]]
32 | handlers = ["tls", "http"]
33 | port = 443
34 |
35 | [[services.tcp_checks]]
36 | grace_period = "1s"
37 | interval = "15s"
38 | restart_limit = 0
39 | timeout = "2s"
40 |
--------------------------------------------------------------------------------
/migrations/2022-10-27-193452_create_plugins_table/up.sql:
--------------------------------------------------------------------------------
1 | -- Your SQL goes here
2 | create table plugins (
3 | id SERIAL PRIMARY KEY,
4 | name VARCHAR NOT NULL,
5 | user_id INTEGER NOT NULL,
6 | updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
7 | created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
8 | display_name VARCHAR NOT NULL,
9 | description VARCHAR NOT NULL,
10 | downloads INTEGER NOT NULL DEFAULT 0,
11 | repository VARCHAR,
12 | wasm bool NOT NULL DEFAULT true,
13 | CONSTRAINT "plugins_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id")
14 | );
15 |
16 | CREATE UNIQUE INDEX plugins_user_id_name ON plugins (user_id, name);
17 | CREATE INDEX plugins_downloads ON plugins (downloads);
18 |
--------------------------------------------------------------------------------
/volts-back/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "volts-back"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 |
8 | [dependencies]
9 | semver = "1.0.14"
10 | rust-s3 = { version = "0.32.3", features = ["with-tokio"] }
11 | tempfile = "3.3.0"
12 | tar = "0.4.38"
13 | sha2 = "0.10.6"
14 | rand = "0.8.5"
15 | chrono = "0.4.22"
16 | diesel = { version = "2.0.2", features = ["postgres", "chrono"] }
17 | diesel-async = { version = "0.1.1", features = ["postgres", "deadpool"] }
18 | async-session = "3.0.0"
19 | headers = "0.3"
20 | axum = { version = "0.6.0-rc.4", features = ["headers"] }
21 | reqwest = { version = "0.11.12", features = ["json"] }
22 | oauth2 = "4.2.3"
23 | anyhow = "1.0.66"
24 | serde_json = "1.0.87"
25 | serde = { version = "1.0", features = ["derive"] }
26 | futures = "0.3"
27 | tokio-util = { version = "0.7", features = ["io"] }
28 | tokio = { version = "1.21.2", features = ["full"] }
29 | dotenvy = "0.15.6"
30 | volts-core = { path = "../volts-core" }
31 | toml_edit = { version = "0.14.4", features = ["easy"] }
32 | lapce-rpc = "0.2.1"
33 | zstd = { version = "0.11" }
--------------------------------------------------------------------------------
/volts-back/src/util.rs:
--------------------------------------------------------------------------------
1 | use rand::{distributions::Uniform, rngs::OsRng, Rng};
2 | use sha2::{Digest, Sha256};
3 |
4 | pub struct SecureToken {
5 | plaintext: String,
6 | token: Vec,
7 | }
8 |
9 | impl SecureToken {
10 | pub fn new_token() -> Self {
11 | let plaintext = generate_secure_alphanumeric_string(32);
12 | let token = Sha256::digest(plaintext.as_bytes()).as_slice().to_vec();
13 | Self { plaintext, token }
14 | }
15 |
16 | pub fn parse(plaintext: &str) -> Self {
17 | let token = Sha256::digest(plaintext.as_bytes()).as_slice().to_vec();
18 | Self {
19 | plaintext: plaintext.to_string(),
20 | token,
21 | }
22 | }
23 |
24 | pub fn plaintext(&self) -> &str {
25 | &self.plaintext
26 | }
27 |
28 | pub fn token(&self) -> &[u8] {
29 | &self.token
30 | }
31 | }
32 |
33 | fn generate_secure_alphanumeric_string(len: usize) -> String {
34 | const CHARS: &[u8] = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
35 |
36 | OsRng
37 | .sample_iter(Uniform::from(0..CHARS.len()))
38 | .map(|idx| CHARS[idx] as char)
39 | .take(len)
40 | .collect()
41 | }
42 |
--------------------------------------------------------------------------------
/nginx/nginx.conf:
--------------------------------------------------------------------------------
1 | user www-data;
2 | worker_processes auto;
3 | pid /run/nginx.pid;
4 | include /etc/nginx/modules-enabled/*.conf;
5 |
6 | events {
7 | worker_connections 768;
8 | # multi_accept on;
9 | }
10 |
11 | http {
12 |
13 | ##
14 | # Basic Settings
15 | ##
16 |
17 | sendfile on;
18 | tcp_nopush on;
19 | types_hash_max_size 2048;
20 | # server_tokens off;
21 |
22 | # server_names_hash_bucket_size 64;
23 | # server_name_in_redirect off;
24 |
25 | include /etc/nginx/mime.types;
26 | default_type application/octet-stream;
27 |
28 | ##
29 | # SSL Settings
30 | ##
31 |
32 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
33 | ssl_prefer_server_ciphers on;
34 |
35 | ##
36 | # Logging Settings
37 | ##
38 |
39 | access_log /var/log/nginx/access.log;
40 | error_log /var/log/nginx/error.log;
41 |
42 | ##
43 | # Gzip Settings
44 | ##
45 |
46 | gzip on;
47 |
48 | # gzip_vary on;
49 | # gzip_proxied any;
50 | # gzip_comp_level 6;
51 | # gzip_buffers 16 8k;
52 | # gzip_http_version 1.1;
53 | # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
54 |
55 | ##
56 | # Virtual Host Configs
57 | ##
58 |
59 | include /etc/nginx/conf.d/*.conf;
60 | include /etc/nginx/sites-enabled/*;
61 | }
62 |
--------------------------------------------------------------------------------
/migrations/00000000000000_diesel_initial_setup/up.sql:
--------------------------------------------------------------------------------
1 | -- This file was automatically created by Diesel to setup helper functions
2 | -- and other internal bookkeeping. This file is safe to edit, any future
3 | -- changes will be added to existing projects as new migrations.
4 |
5 |
6 |
7 |
8 | -- Sets up a trigger for the given table to automatically set a column called
9 | -- `updated_at` whenever the row is modified (unless `updated_at` was included
10 | -- in the modified columns)
11 | --
12 | -- # Example
13 | --
14 | -- ```sql
15 | -- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
16 | --
17 | -- SELECT diesel_manage_updated_at('users');
18 | -- ```
19 | CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
20 | BEGIN
21 | EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
22 | FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
23 | END;
24 | $$ LANGUAGE plpgsql;
25 |
26 | CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
27 | BEGIN
28 | IF (
29 | NEW IS DISTINCT FROM OLD AND
30 | NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
31 | ) THEN
32 | NEW.updated_at := current_timestamp;
33 | END IF;
34 | RETURN NEW;
35 | END;
36 | $$ LANGUAGE plpgsql;
37 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM rust:latest as builder
2 |
3 | RUN cargo install wasm-pack
4 |
5 | WORKDIR /build
6 | COPY . .
7 | RUN --mount=type=cache,target=/usr/local/cargo/registry \
8 | # --mount=type=cache,target=/build/target \
9 | cd ./volts-front && \
10 | wasm-pack build --target web && \
11 | cd .. && \
12 | cargo build --bin volts-server --release
13 |
14 | # Runtime image
15 | FROM debian:bookworm
16 |
17 | RUN apt-get update
18 | RUN apt install -y postgresql-common
19 | RUN /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -i -v 14
20 | RUN apt-get -y install postgresql-client-14
21 | RUN apt-get -y install nginx
22 | RUN apt-get install ca-certificates -y
23 | RUN update-ca-certificates
24 |
25 | WORKDIR /app
26 | RUN mkdir /app/static
27 |
28 | COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
29 | COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
30 | COPY ./nginx/mime.types /etc/nginx/mime.types
31 | COPY ./nginx/index.html /app/static/index.html
32 | COPY ./nginx/volt.png /app/static/volt.png
33 | COPY ./volts-front/assets/tailwind.css /app/static/main.css
34 |
35 | # Get compiled binaries from builder's cargo install directory
36 | COPY --from=builder /build/volts-front/pkg/volts_front.js /app/static/main.js
37 | COPY --from=builder /build/volts-front/pkg/volts_front_bg.wasm /app/static/main.wasm
38 | COPY --from=builder /build/target/release/volts-server /app/volts-server
39 |
40 | CMD nginx && /app/volts-server
41 |
--------------------------------------------------------------------------------
/volts-core/src/lib.rs:
--------------------------------------------------------------------------------
1 | pub mod db;
2 | pub mod util;
3 |
4 | #[macro_use]
5 | extern crate diesel;
6 |
7 | use chrono::NaiveDateTime;
8 | use db::models::ApiToken;
9 | use serde::{Deserialize, Serialize};
10 |
11 | #[derive(Serialize, Deserialize)]
12 | pub struct MeUser {
13 | pub login: String,
14 | }
15 |
16 | #[derive(Serialize, Deserialize)]
17 | pub struct NewSessionResponse {
18 | pub url: String,
19 | pub state: String,
20 | }
21 |
22 | #[derive(Serialize, Deserialize, Clone)]
23 | pub struct ApiTokenList {
24 | pub api_tokens: Vec,
25 | }
26 |
27 | #[derive(Serialize, Deserialize)]
28 | pub struct EncodeApiToken {
29 | pub token: ApiToken,
30 | pub plaintext: String,
31 | }
32 |
33 | #[derive(Serialize, Deserialize)]
34 | pub struct NewTokenPayload {
35 | pub name: String,
36 | }
37 |
38 | #[derive(Serialize, Deserialize, PartialEq, Eq, Clone)]
39 | pub struct EncodePlugin {
40 | pub id: i32,
41 | pub name: String,
42 | pub author: String,
43 | pub version: String,
44 | pub display_name: String,
45 | pub description: String,
46 | pub downloads: i32,
47 | pub repository: Option,
48 | pub updated_at_ts: i64,
49 | pub updated_at: String,
50 | pub released_at: String,
51 | pub wasm: bool,
52 | }
53 |
54 | #[derive(Serialize, Deserialize)]
55 | pub struct PluginList {
56 | pub total: i64,
57 | pub limit: usize,
58 | pub offset: usize,
59 | pub plugins: Vec,
60 | }
61 |
--------------------------------------------------------------------------------
/volts-core/src/db/schema.rs:
--------------------------------------------------------------------------------
1 | // @generated automatically by Diesel CLI.
2 |
3 | diesel::table! {
4 | api_tokens (id) {
5 | id -> Int4,
6 | user_id -> Int4,
7 | token -> Bytea,
8 | name -> Varchar,
9 | created_at -> Timestamp,
10 | last_used_at -> Nullable,
11 | revoked -> Bool,
12 | }
13 | }
14 |
15 | diesel::table! {
16 | plugins (id) {
17 | id -> Int4,
18 | name -> Varchar,
19 | user_id -> Int4,
20 | updated_at -> Timestamp,
21 | created_at -> Timestamp,
22 | display_name -> Varchar,
23 | description -> Varchar,
24 | downloads -> Int4,
25 | repository -> Nullable,
26 | wasm -> Bool,
27 | }
28 | }
29 |
30 | diesel::table! {
31 | users (id) {
32 | id -> Int4,
33 | gh_access_token -> Varchar,
34 | gh_login -> Varchar,
35 | gh_id -> Int4,
36 | }
37 | }
38 |
39 | diesel::table! {
40 | versions (id) {
41 | id -> Int4,
42 | plugin_id -> Int4,
43 | updated_at -> Timestamp,
44 | created_at -> Timestamp,
45 | num -> Varchar,
46 | yanked -> Bool,
47 | downloads -> Int4,
48 | }
49 | }
50 |
51 | diesel::joinable!(api_tokens -> users (user_id));
52 | diesel::joinable!(plugins -> users (user_id));
53 | diesel::joinable!(versions -> plugins (plugin_id));
54 |
55 | diesel::allow_tables_to_appear_in_same_query!(api_tokens, plugins, users, versions,);
56 |
--------------------------------------------------------------------------------
/volts-core/src/util/rfc3339.rs:
--------------------------------------------------------------------------------
1 | //! Convenience functions for serializing and deserializing times in RFC 3339 format.
2 | //! Used for returning time values in JSON API responses.
3 | //! Example: `2012-02-22T14:53:18+00:00`.
4 |
5 | use chrono::{DateTime, NaiveDateTime, Utc};
6 | use serde::{self, Deserialize, Deserializer, Serializer};
7 |
8 | pub fn serialize(dt: &NaiveDateTime, serializer: S) -> Result
9 | where
10 | S: Serializer,
11 | {
12 | let s = DateTime::::from_utc(*dt, Utc).to_rfc3339();
13 | serializer.serialize_str(&s)
14 | }
15 | pub fn deserialize<'de, D>(deserializer: D) -> Result
16 | where
17 | D: Deserializer<'de>,
18 | {
19 | let s = String::deserialize(deserializer)?;
20 | let dt = DateTime::parse_from_rfc3339(&s).map_err(serde::de::Error::custom)?;
21 | Ok(dt.naive_utc())
22 | }
23 |
24 | /// Wrapper for dealing with Option
25 | pub mod option {
26 | use chrono::NaiveDateTime;
27 | use serde::{Deserializer, Serializer};
28 |
29 | pub fn serialize(dt: &Option, serializer: S) -> Result
30 | where
31 | S: Serializer,
32 | {
33 | match *dt {
34 | Some(dt) => super::serialize(&dt, serializer),
35 | None => serializer.serialize_none(),
36 | }
37 | }
38 |
39 | pub fn deserialize<'de, D>(deserializer: D) -> Result