Compare commits
No commits in common. "7e3be70a8f971d085869f2012d23cf7e965a71c9" and "2cbcd06c1a6242d2498765b819f2c6aa41f7d61f" have entirely different histories.
7e3be70a8f
...
2cbcd06c1a
|
@ -8,7 +8,6 @@ services:
|
||||||
bfile:
|
bfile:
|
||||||
volumes:
|
volumes:
|
||||||
- './filed:/opt/code'
|
- './filed:/opt/code'
|
||||||
- '/opt/code/target'
|
|
||||||
- './volatile/files:/opt/user_uploads'
|
- './volatile/files:/opt/user_uploads'
|
||||||
caddy:
|
caddy:
|
||||||
image: caddy:alpine
|
image: caddy:alpine
|
||||||
|
|
|
@ -1,89 +0,0 @@
|
||||||
openapi: 3.0.3
|
|
||||||
info:
|
|
||||||
title: blek! File (fileD) File API
|
|
||||||
description: |-
|
|
||||||
This document describes the API of the File API of blek! File fileD.
|
|
||||||
|
|
||||||
This API has optional api key authorization, which should be located in the env file.
|
|
||||||
version: 0.0.1
|
|
||||||
servers:
|
|
||||||
- url: http://localhost
|
|
||||||
description: Local staging environment
|
|
||||||
paths:
|
|
||||||
/api/get_all:
|
|
||||||
get:
|
|
||||||
summary: Get all files
|
|
||||||
description: |-
|
|
||||||
Get all files available.
|
|
||||||
|
|
||||||
Returns an array of strings with no metadata.
|
|
||||||
security:
|
|
||||||
- apikey: [ key ]
|
|
||||||
responses:
|
|
||||||
200:
|
|
||||||
description: An array of file IDs
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: array
|
|
||||||
items:
|
|
||||||
type: string
|
|
||||||
example: [ 'ZnVjayBwdXRpbg' ]
|
|
||||||
/api/delete:
|
|
||||||
post:
|
|
||||||
summary: Delete a file
|
|
||||||
description: |-
|
|
||||||
Deletes a file thats been uploaded.
|
|
||||||
|
|
||||||
It will work if one of the two conditions are met:
|
|
||||||
1. The requester's IP is the same as the uploader IP
|
|
||||||
2. The request is authorized with an API key
|
|
||||||
security:
|
|
||||||
- apikey: [ key ]
|
|
||||||
responses:
|
|
||||||
200:
|
|
||||||
description: |-
|
|
||||||
The file has been deleted
|
|
||||||
|
|
||||||
Returns an empty object for future extension
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
example: {}
|
|
||||||
|
|
||||||
components:
|
|
||||||
|
|
||||||
schemas:
|
|
||||||
File:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
path:
|
|
||||||
type: string
|
|
||||||
description: Path to the file in fileD's filesystem
|
|
||||||
example: 1
|
|
||||||
size:
|
|
||||||
type: integer
|
|
||||||
description: Size of the file in bytes
|
|
||||||
example: 10
|
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
description: (optional) Name of the file
|
|
||||||
example: null
|
|
||||||
mime:
|
|
||||||
type: string
|
|
||||||
description: MIME type of the file
|
|
||||||
example: text/plain
|
|
||||||
delete_at:
|
|
||||||
type: string
|
|
||||||
description: TimeDate when the file will be deleted
|
|
||||||
example: '1984-01-01T00:00:00.000Z'
|
|
||||||
sha512:
|
|
||||||
type: string
|
|
||||||
example: 417e1ec1a0e82aac809da7e5aa309e03bf47eaa96ab2e335f5bb739d062d835b04ccebb89214bd5a54879527789a81ae4e9deab813e4212c757b36d08fa8165a
|
|
||||||
|
|
||||||
securitySchemes:
|
|
||||||
apikey:
|
|
||||||
type: http
|
|
||||||
scheme: bearer
|
|
||||||
description: Optional authorization, as defined in the instance-specific config file
|
|
|
@ -1,27 +1,18 @@
|
||||||
use warp::{reply::Reply, reject::Rejection, Filter};
|
use warp::{reply::Reply, reject::Rejection, Filter};
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
|
|
||||||
use self::get_all::get_all_f;
|
|
||||||
|
|
||||||
use super::state::SharedState;
|
use super::state::SharedState;
|
||||||
|
|
||||||
mod get_all;
|
mod get_all;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct APIError {
|
|
||||||
error: String
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn api_root() -> Box<dyn Reply> {
|
pub fn api_root() -> Box<dyn Reply> {
|
||||||
let err = APIError {
|
Box::new(warp::reply::json(&String::from("{ error: \"You have called the API root of a blek! File instance. Refer to https://git.blek.codes/blek/bfile.git for documentation.\" }")))
|
||||||
error: "You have called the API root of a blek! File instance. Refer to https://git.blek.codes/blek/bfile.git for documentation.".into()
|
|
||||||
};
|
|
||||||
Box::new(warp::reply::json(&err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_routes(state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
pub fn get_routes(state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
||||||
warp::path!("api")
|
let api = warp::path!("api");
|
||||||
|
let api = api
|
||||||
.and(warp::path::end())
|
.and(warp::path::end())
|
||||||
.map(api_root)
|
.map(api_root)
|
||||||
.or(get_all_f(state))
|
.or(get_all::get_all_f(state));
|
||||||
|
api
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@ pub async fn get_all(_state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_all_f(state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
pub fn get_all_f(state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
||||||
warp::path!("api" / "get_all")
|
warp::path!("get_all")
|
||||||
.map(move || state.clone())
|
.map(move || state.clone())
|
||||||
.and_then(get_all)
|
.and_then(get_all)
|
||||||
}
|
}
|
Loading…
Reference in New Issue