Skip to content

Commit

Permalink
first draft of media api
Browse files Browse the repository at this point in the history
  • Loading branch information
thebino committed Jul 15, 2023
1 parent 6c868ee commit 212fcaa
Show file tree
Hide file tree
Showing 24 changed files with 363 additions and 91 deletions.
18 changes: 10 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ members = [
"crates/oauth_authorization_server",
"crates/oauth_authentication",
"crates/core_common",
"crates/core_photos",
"crates/media",
"crates/activity_pub",
"crates/plugin_interface"
]
Expand All @@ -37,7 +37,7 @@ members = [
oauth_authorization_server = { path = "./crates/oauth_authorization_server" }
oauth_authentication = { path = "./crates/oauth_authentication" }
core_common = { path = "./crates/core_common" }
core_photos = { path = "./crates/core_photos" }
media = { path = "./crates/media" }
activity_pub = { path = "./crates/activity_pub" }

activitypub_federation = "~0.4.0"
Expand Down Expand Up @@ -80,7 +80,7 @@ oauth_authorization_server = { workspace = true }
oauth_authentication = { workspace = true }
# core_api = { workspace = true }
core_common = { workspace = true }
core_photos = { workspace = true }
media = { workspace = true }
activity_pub = { workspace = true }
# core_api_crud = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

Photos.network · A privacy first photo storage and sharing service for fediverse.
Photos.network · A privacy first, self-hosted photo storage and sharing service for fediverse.
Copyright 2020 Photos network developers

This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/photos-network/core/check%20code%20quality)


[Photos.network](https://photos.network) is a privacy first photo storage and sharing service for fediverse.
[Photos.network](https://photos.network) is a free and open source, privacy first, self-hosted photo storage and sharing service for fediverse.

Its core features are:

Expand Down
80 changes: 80 additions & 0 deletions crates/accounts/router.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* Photos.network · A privacy first photo storage and sharing service for fediverse.
* Copyright (C) 2020 Photos network developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use axum::routing::get;
use axum::Router;
use handler::{
authorize::authorization_handler,
discovery::openid_discover_handler,
jwks::openid_jwks_handler,
login::{get_realm_login_form, post_realm_login},
};
use state::ServerState;
use std::sync::{Arc, RwLock};

pub mod client;
pub mod config;
pub mod error;
pub mod query;
pub mod realm;
pub mod request;
pub mod state;
pub mod handler {
pub mod authorize;
pub mod discovery;
pub mod jwks;
pub mod login;
}

pub struct AccountsApi {}

impl AccountsApi {
pub fn routes<S>() -> Router<S>
where
S: Send + Sync + 'static + Clone,
{
Router::new()
// Returns information about a single account by ID
// 200 OK
// 401 Unauthorized - Requesting user is unauthenticated
// 404 Not Found - The requested resource does not exist.
.route("/users/:user_id/profile", get(list_photos_handler))
// Update a single account when `admin.users:write` scope is present
// 200 - OK
// 400 Bad Request - The request body was malformed or a field violated its constraints.
// 401 Unauthorized - You are unauthenticated
// 403 Forbidden - You are authenticated but have no permission to manage the target user.
// 404 Not Found - The requested resource does not exist.
.route("/users/:user_id/profile", patch(list_photos_handler))

// Disable a single account by ID when `admin.users:write` scope is present
// 204 No Content - Account was disabled successful
// 401 Unauthorized - You are unauthenticated
// 403 Forbidden - You are authenticated but have no permission to manage the target user.
// 404 Not Found - The requested resource does not exist.
.route("/users/:user_id/disable", patch(list_photos_handler))

// Enable a single account by ID when `admin.users:write` scope is present
// 204 No Content - Account was enabled successful
// 401 Unauthorized - You are unauthenticated
// 403 Forbidden - You are authenticated but have no permission to manage the target user.
// 404 Not Found - The requested resource does not exist.
.route("/users/:user_id/enabled", patch(list_photos_handler))

.layer(tower_http::trace::TraceLayer::new_for_http())
}
}
3 changes: 0 additions & 3 deletions crates/core_photos/README.md

This file was deleted.

10 changes: 7 additions & 3 deletions crates/core_photos/Cargo.toml → crates/media/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "core_photos"
name = "media"
description = "Manages all media items in the database and on filesystem."
version.workspace = true
authors.workspace = true
description.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true
Expand All @@ -11,9 +11,13 @@ license.workspace = true
edition.workspace = true

[lib]
name = "core_photos"
name = "media"
path = "src/lib.rs"
doctest = false

[dependencies]
serde = { workspace = true, features = ["derive"] }

# Router
axum = { workspace = true }
tower-http.workspace = true
6 changes: 6 additions & 0 deletions crates/media/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# media

This crate handles all media items like photos or albums for [Photos.network](https://photos.network).

Persisting the metadata in a database with [SQLx](https://crates.io/crates/sqlx) and accessing the files via [filesystem](https://crates.io/crates/filesystem).

14 changes: 14 additions & 0 deletions crates/media/src/api/handler/file_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Returns the binary of a given entity
//!

use axum::http::StatusCode;

pub(crate) async fn file_handler() -> std::result::Result<String, StatusCode> {
// TODO: parse params max-with / max-height =wmax-width-hmax-height (=w2048-h1024)
// -wmax-width (preserving the aspect ratio)
// -hmax-height (preserving the aspect ratio)
// -c crop images to max-width / max-height
// -d remove exif data

Err(StatusCode::NOT_IMPLEMENTED)
}
7 changes: 7 additions & 0 deletions crates/media/src/api/handler/list_photos_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Returns a list of media items owned or shared with the user
//!
pub(crate) async fn list_photos_handler(

) -> std::result::Result<String, StatusCode> {
Err(StatusCode::NOT_IMPLEMENTED)
}
7 changes: 7 additions & 0 deletions crates/media/src/api/handler/photo_details.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Returns the details of a given media item
//!
pub(crate) async fn photo_details_handler(

) -> std::result::Result<String, StatusCode> {
Err(StatusCode::NOT_IMPLEMENTED)
}
52 changes: 52 additions & 0 deletions crates/media/src/api/router.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Photos.network · A privacy first photo storage and sharing service for fediverse.
* Copyright (C) 2020 Photos network developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use crate::api::handler::file_handler::file_handler;
use axum::routing::{get, patch, post};
use axum::Router;

pub struct MediaApi {}

impl MediaApi {
pub fn routes<S>() -> Router<S>
where
S: Send + Sync + 'static + Clone,
{
Router::new()
// list owned and shared items
.route("/photos", get(file_handler))
// get metadata of a specific item
.route("/photos/:entity_id", get(file_handler))
// update the given media item owned by the user
.route("/photos/:entity_id", patch(file_handler))
// creates one or multiple media items
.route("/photos", post(file_handler))
// list owned and shared albums
.route("/albums", get(file_handler))
// create new album
.route("/albums", post(file_handler))
// get metadata of a specific owned or shared album
.route("/albums/:entity_id", get(file_handler))
// updates the given album owned by the user
.route("/albums/:entity_id", patch(file_handler))
// shares the given album
.route("/albums/:entity_id/share", patch(file_handler))
// unshares the given album
.route("/albums/:entity_id/unshare", patch(file_handler))
.layer(tower_http::trace::TraceLayer::new_for_http())
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions crates/core_photos/src/lib.rs → crates/media/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@
pub mod data {
pub mod error;
}

pub mod api {
pub mod handler {
pub mod file_handler;
}
pub mod router;
}
File renamed without changes.
Loading

0 comments on commit 212fcaa

Please sign in to comment.