mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 00:55:25 +00:00
remove(labrinth): old shared instances impl (#6760)
This commit is contained in:
Generated
-16
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n INSERT INTO shared_instance_users (user_id, shared_instance_id, permissions)\n VALUES ($1, $2, $3)\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Int8",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "09ebec1a568edf1959f20b33d8ba2b8edb55d93ada8f2243448865163f555d8d"
|
||||
}
|
||||
Generated
-46
@@ -1,46 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT id, title, owner_id, public, current_version_id\n FROM shared_instances\n WHERE id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "title",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "owner_id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "public",
|
||||
"type_info": "Bool"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "current_version_id",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "1ebe19b7b4f10039065967a0b1ca4bb38acc54e4ea5de020fffef7457000fa6e"
|
||||
}
|
||||
Generated
-46
@@ -1,46 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT id, shared_instance_id, size, sha512, created\n FROM shared_instance_versions\n WHERE shared_instance_id = $1\n ORDER BY created DESC\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "shared_instance_id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "size",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "sha512",
|
||||
"type_info": "Bytea"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "created",
|
||||
"type_info": "Timestamptz"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "265c4d6f33714c8a5cf3137c429e2b57e917e9507942d65f40c1b733209cabf0"
|
||||
}
|
||||
Generated
-14
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n\t\t\t\tDELETE FROM shared_instance_invited_users\n\t\t\t\tWHERE invited_user_id = $1\n\t\t\t\t",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "3a2a1962875e5164d3d20802886db93631d57be2fe82bc2986dffd878ef1174d"
|
||||
}
|
||||
Generated
-14
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n DELETE FROM shared_instance_versions\n WHERE id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "47130ef29ce5914528e5424fe516a9158a3ea08f8720f6df5b4902cd8094d3bb"
|
||||
}
|
||||
Generated
-15
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE shared_instances SET current_version_id = $1 WHERE id = $2",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "47ec9f179f1c52213bd32b37621ab13ae43d180b8c86cb2a6fab0253dd4eba55"
|
||||
}
|
||||
Generated
-15
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE shared_instances\n SET public = $1\n WHERE id = $2\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Bool",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "6b166d129b0ee028898620054a58fa4c3641eb2221e522bf50abad4f5e977599"
|
||||
}
|
||||
Generated
-17
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n INSERT INTO shared_instances (id, title, owner_id, current_version_id)\n VALUES ($1, $2, $3, $4)\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Varchar",
|
||||
"Int8",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "6f72c853e139f23322fe6f1f02e4e07e5ae80b5dfca6dc041a03c0c7a30a5cf1"
|
||||
}
|
||||
Generated
-15
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE shared_instances\n SET owner_id = $1\n WHERE owner_id = $2\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "72ae0e8debd06067894a2f7bea279446dd964da4efa49c5464cebde57860f741"
|
||||
}
|
||||
Generated
-22
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT EXISTS(SELECT 1 FROM shared_instance_versions WHERE id=$1)",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "exists",
|
||||
"type_info": "Bool"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "7c445073f61e30723416a9690aa9d227d95f2a8f2eb9852833e14c723903988b"
|
||||
}
|
||||
Generated
-46
@@ -1,46 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n -- See https://github.com/launchbadge/sqlx/issues/1266 for why we need all the \"as\"\n SELECT\n id as \"id!\",\n title as \"title!\",\n public as \"public!\",\n owner_id as \"owner_id!\",\n current_version_id\n FROM shared_instances\n WHERE owner_id = $1\n UNION\n SELECT\n id as \"id!\",\n title as \"title!\",\n public as \"public!\",\n owner_id as \"owner_id!\",\n current_version_id\n FROM shared_instances\n JOIN shared_instance_users ON id = shared_instance_id\n WHERE user_id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id!",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "title!",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "public!",
|
||||
"type_info": "Bool"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "owner_id!",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "current_version_id",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "9c6e18cb19251e54b3b96446ab88d84842152b82c9a0032d1db587d7099b8550"
|
||||
}
|
||||
Generated
-15
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE shared_instances\n SET title = $1\n WHERE id = $2\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Varchar",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "9ccaf8ea52b1b6f0880d34cdb4a9405e28c265bef6121b457c4f39cacf00683f"
|
||||
}
|
||||
Generated
-34
@@ -1,34 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT shared_instance_id, user_id, permissions\n FROM shared_instance_users\n WHERE shared_instance_id = ANY($1)\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "shared_instance_id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "user_id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "permissions",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8Array"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "aec58041cf5e5e68501652336581b8c709645ef29f3b5fb6e8e07fc212b36798"
|
||||
}
|
||||
Generated
-46
@@ -1,46 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT id, shared_instance_id, size, sha512, created\n FROM shared_instance_versions\n WHERE id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "shared_instance_id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "size",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "sha512",
|
||||
"type_info": "Bytea"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "created",
|
||||
"type_info": "Timestamptz"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "b93253bbc35b24974d13bc8ee0447be2a18275f33f8991d910f693fbcc1ff731"
|
||||
}
|
||||
Generated
-23
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT permissions\n FROM shared_instance_users\n WHERE shared_instance_id = $1 AND user_id = $2\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "permissions",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "c3869a595693757ccf81085d0c8eb2231578aff18c93d02ead97c3c07f0b27ea"
|
||||
}
|
||||
Generated
-14
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n DELETE FROM shared_instances\n WHERE id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "cef730c02bb67b0536d35e5aaca0bd34c3893e8b55bbd126a988137ec7bf1ff9"
|
||||
}
|
||||
Generated
-22
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT EXISTS(SELECT 1 FROM shared_instances WHERE id=$1)",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "exists",
|
||||
"type_info": "Bool"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "d8558a8039ade3b383db4f0e095e6826f46c27ab3a21520e9e169fd1491521c4"
|
||||
}
|
||||
Generated
-18
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n INSERT INTO shared_instance_versions (id, shared_instance_id, size, sha512, created)\n VALUES ($1, $2, $3, $4, $5)\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Int8",
|
||||
"Int8",
|
||||
"Bytea",
|
||||
"Timestamptz"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "d8a1d710f86b3df4d99c2d2ec26ec405531e4270be85087122245991ec88473e"
|
||||
}
|
||||
Generated
-14
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n\t\t\t\tDELETE FROM shared_instance_users\n\t\t\t\tWHERE user_id = $1\n\t\t\t\t",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "d926d015cece307da567ac44b84d3e7416723ff95fcd83587f113621a9887420"
|
||||
}
|
||||
Generated
-14
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE shared_instances\n SET current_version_id = (\n SELECT id FROM shared_instance_versions\n WHERE shared_instance_id = $1\n ORDER BY created DESC\n LIMIT 1\n )\n WHERE id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "f6388b5026e25191840d1a157a9ed48aaedab5db381f4efc389b852d9020a0e6"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
DROP TABLE IF EXISTS shared_instance_versions CASCADE;
|
||||
DROP TABLE IF EXISTS shared_instance_invite_links CASCADE;
|
||||
DROP TABLE IF EXISTS shared_instance_invited_users CASCADE;
|
||||
DROP TABLE IF EXISTS shared_instance_users CASCADE;
|
||||
DROP TABLE IF EXISTS shared_instances CASCADE;
|
||||
@@ -5,9 +5,8 @@ use crate::models::ids::{
|
||||
ChargeId, CollectionId, FileId, ImageId, NotificationId,
|
||||
OAuthAccessTokenId, OAuthClientAuthorizationId, OAuthClientId,
|
||||
OAuthRedirectUriId, OrganizationId, PasskeyId, PatId, PayoutId, ProductId,
|
||||
ProductPriceId, ProjectId, ReportId, SessionId, SharedInstanceId,
|
||||
SharedInstanceVersionId, TeamId, TeamMemberId, ThreadId, ThreadMessageId,
|
||||
UserSubscriptionId, VersionId,
|
||||
ProductPriceId, ProjectId, ReportId, SessionId, TeamId, TeamMemberId,
|
||||
ThreadId, ThreadMessageId, UserSubscriptionId, VersionId,
|
||||
};
|
||||
use ariadne::ids::base62_impl::to_base62;
|
||||
use ariadne::ids::{UserId, random_base62_rng, random_base62_rng_range};
|
||||
@@ -238,14 +237,6 @@ db_id_interface!(
|
||||
SessionId,
|
||||
generator: generate_session_id @ "sessions",
|
||||
);
|
||||
db_id_interface!(
|
||||
SharedInstanceId,
|
||||
generator: generate_shared_instance_id @ "shared_instances",
|
||||
);
|
||||
db_id_interface!(
|
||||
SharedInstanceVersionId,
|
||||
generator: generate_shared_instance_version_id @ "shared_instance_versions",
|
||||
);
|
||||
db_id_interface!(
|
||||
TeamId,
|
||||
generator: generate_team_id @ "teams",
|
||||
|
||||
@@ -32,7 +32,6 @@ pub mod products_tax_identifier_item;
|
||||
pub mod project_item;
|
||||
pub mod report_item;
|
||||
pub mod session_item;
|
||||
pub mod shared_instance_item;
|
||||
pub mod team_item;
|
||||
pub mod thread_item;
|
||||
pub mod user_item;
|
||||
|
||||
@@ -1,336 +0,0 @@
|
||||
use crate::database::PgTransaction;
|
||||
use crate::database::models::{
|
||||
DBSharedInstanceId, DBSharedInstanceVersionId, DBUserId,
|
||||
};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::shared_instances::SharedInstanceUserPermissions;
|
||||
use chrono::{DateTime, Utc};
|
||||
use dashmap::DashMap;
|
||||
use futures_util::TryStreamExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
//region shared_instances
|
||||
pub struct DBSharedInstance {
|
||||
pub id: DBSharedInstanceId,
|
||||
pub title: String,
|
||||
pub owner_id: DBUserId,
|
||||
pub public: bool,
|
||||
pub current_version_id: Option<DBSharedInstanceVersionId>,
|
||||
}
|
||||
|
||||
struct SharedInstanceQueryResult {
|
||||
id: i64,
|
||||
title: String,
|
||||
owner_id: i64,
|
||||
public: bool,
|
||||
current_version_id: Option<i64>,
|
||||
}
|
||||
|
||||
impl From<SharedInstanceQueryResult> for DBSharedInstance {
|
||||
fn from(val: SharedInstanceQueryResult) -> Self {
|
||||
DBSharedInstance {
|
||||
id: DBSharedInstanceId(val.id),
|
||||
title: val.title,
|
||||
owner_id: DBUserId(val.owner_id),
|
||||
public: val.public,
|
||||
current_version_id: val
|
||||
.current_version_id
|
||||
.map(DBSharedInstanceVersionId),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DBSharedInstance {
|
||||
pub async fn insert(
|
||||
&self,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO shared_instances (id, title, owner_id, current_version_id)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
",
|
||||
self.id as DBSharedInstanceId,
|
||||
self.title,
|
||||
self.owner_id as DBUserId,
|
||||
self.current_version_id.map(|x| x.0),
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get(
|
||||
id: DBSharedInstanceId,
|
||||
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||
) -> Result<Option<Self>, sqlx::Error> {
|
||||
let result = sqlx::query_as!(
|
||||
SharedInstanceQueryResult,
|
||||
"
|
||||
SELECT id, title, owner_id, public, current_version_id
|
||||
FROM shared_instances
|
||||
WHERE id = $1
|
||||
",
|
||||
id.0,
|
||||
)
|
||||
.fetch_optional(exec)
|
||||
.await?;
|
||||
|
||||
Ok(result.map(Into::into))
|
||||
}
|
||||
|
||||
pub async fn list_for_user(
|
||||
user: DBUserId,
|
||||
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||
) -> Result<Vec<Self>, sqlx::Error> {
|
||||
let results = sqlx::query_as!(
|
||||
SharedInstanceQueryResult,
|
||||
r#"
|
||||
-- See https://github.com/launchbadge/sqlx/issues/1266 for why we need all the "as"
|
||||
SELECT
|
||||
id as "id!",
|
||||
title as "title!",
|
||||
public as "public!",
|
||||
owner_id as "owner_id!",
|
||||
current_version_id
|
||||
FROM shared_instances
|
||||
WHERE owner_id = $1
|
||||
UNION
|
||||
SELECT
|
||||
id as "id!",
|
||||
title as "title!",
|
||||
public as "public!",
|
||||
owner_id as "owner_id!",
|
||||
current_version_id
|
||||
FROM shared_instances
|
||||
JOIN shared_instance_users ON id = shared_instance_id
|
||||
WHERE user_id = $1
|
||||
"#,
|
||||
user.0,
|
||||
)
|
||||
.fetch_all(exec)
|
||||
.await?;
|
||||
|
||||
Ok(results.into_iter().map(Into::into).collect())
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region shared_instance_users
|
||||
const USERS_NAMESPACE: &str = "shared_instance_users";
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug)]
|
||||
pub struct DBSharedInstanceUser {
|
||||
pub user_id: DBUserId,
|
||||
pub shared_instance_id: DBSharedInstanceId,
|
||||
pub permissions: SharedInstanceUserPermissions,
|
||||
}
|
||||
|
||||
impl DBSharedInstanceUser {
|
||||
pub async fn insert(
|
||||
&self,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO shared_instance_users (user_id, shared_instance_id, permissions)
|
||||
VALUES ($1, $2, $3)
|
||||
",
|
||||
self.user_id as DBUserId,
|
||||
self.shared_instance_id as DBSharedInstanceId,
|
||||
self.permissions.bits() as i64,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_user_permissions(
|
||||
instance_id: DBSharedInstanceId,
|
||||
user_id: DBUserId,
|
||||
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||
) -> Result<Option<SharedInstanceUserPermissions>, super::DatabaseError>
|
||||
{
|
||||
let permissions = sqlx::query!(
|
||||
"
|
||||
SELECT permissions
|
||||
FROM shared_instance_users
|
||||
WHERE shared_instance_id = $1 AND user_id = $2
|
||||
",
|
||||
instance_id as DBSharedInstanceId,
|
||||
user_id as DBUserId,
|
||||
)
|
||||
.fetch_optional(exec)
|
||||
.await?
|
||||
.map(|x| {
|
||||
SharedInstanceUserPermissions::from_bits(x.permissions as u64)
|
||||
.unwrap_or(SharedInstanceUserPermissions::empty())
|
||||
});
|
||||
|
||||
Ok(permissions)
|
||||
}
|
||||
|
||||
pub async fn get_from_instance(
|
||||
instance_id: DBSharedInstanceId,
|
||||
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||
redis: &RedisPool,
|
||||
) -> Result<Vec<DBSharedInstanceUser>, super::DatabaseError> {
|
||||
Self::get_from_instance_many(&[instance_id], exec, redis).await
|
||||
}
|
||||
|
||||
pub async fn get_from_instance_many(
|
||||
instance_ids: &[DBSharedInstanceId],
|
||||
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||
redis: &RedisPool,
|
||||
) -> Result<Vec<DBSharedInstanceUser>, super::DatabaseError> {
|
||||
if instance_ids.is_empty() {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
|
||||
let users = redis
|
||||
.get_cached_keys(
|
||||
USERS_NAMESPACE,
|
||||
&instance_ids.iter().map(|id| id.0).collect::<Vec<_>>(),
|
||||
async |user_ids| {
|
||||
let users = sqlx::query!(
|
||||
"
|
||||
SELECT shared_instance_id, user_id, permissions
|
||||
FROM shared_instance_users
|
||||
WHERE shared_instance_id = ANY($1)
|
||||
",
|
||||
&user_ids
|
||||
)
|
||||
.fetch(exec)
|
||||
.try_fold(DashMap::new(), |acc: DashMap<_, Vec<_>>, m| {
|
||||
acc.entry(m.shared_instance_id).or_default().push(
|
||||
DBSharedInstanceUser {
|
||||
user_id: DBUserId(m.user_id),
|
||||
shared_instance_id: DBSharedInstanceId(
|
||||
m.shared_instance_id,
|
||||
),
|
||||
permissions:
|
||||
SharedInstanceUserPermissions::from_bits(
|
||||
m.permissions as u64,
|
||||
)
|
||||
.unwrap_or(
|
||||
SharedInstanceUserPermissions::empty(),
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
async move { Ok(acc) }
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(users)
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(users.into_iter().flatten().collect())
|
||||
}
|
||||
|
||||
pub async fn clear_cache(
|
||||
instance_id: DBSharedInstanceId,
|
||||
redis: &RedisPool,
|
||||
) -> Result<(), super::DatabaseError> {
|
||||
let mut redis = redis.connect().await?;
|
||||
redis.delete(USERS_NAMESPACE, instance_id.0).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region shared_instance_versions
|
||||
pub struct DBSharedInstanceVersion {
|
||||
pub id: DBSharedInstanceVersionId,
|
||||
pub shared_instance_id: DBSharedInstanceId,
|
||||
pub size: u64,
|
||||
pub sha512: Vec<u8>,
|
||||
pub created: DateTime<Utc>,
|
||||
}
|
||||
|
||||
struct SharedInstanceVersionQueryResult {
|
||||
id: i64,
|
||||
shared_instance_id: i64,
|
||||
size: i64,
|
||||
sha512: Vec<u8>,
|
||||
created: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl From<SharedInstanceVersionQueryResult> for DBSharedInstanceVersion {
|
||||
fn from(val: SharedInstanceVersionQueryResult) -> Self {
|
||||
DBSharedInstanceVersion {
|
||||
id: DBSharedInstanceVersionId(val.id),
|
||||
shared_instance_id: DBSharedInstanceId(val.shared_instance_id),
|
||||
size: val.size as u64,
|
||||
sha512: val.sha512,
|
||||
created: val.created,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DBSharedInstanceVersion {
|
||||
pub async fn insert(
|
||||
&self,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO shared_instance_versions (id, shared_instance_id, size, sha512, created)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
",
|
||||
self.id as DBSharedInstanceVersionId,
|
||||
self.shared_instance_id as DBSharedInstanceId,
|
||||
self.size as i64,
|
||||
self.sha512,
|
||||
self.created,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get(
|
||||
id: DBSharedInstanceVersionId,
|
||||
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||
) -> Result<Option<Self>, sqlx::Error> {
|
||||
let result = sqlx::query_as!(
|
||||
SharedInstanceVersionQueryResult,
|
||||
"
|
||||
SELECT id, shared_instance_id, size, sha512, created
|
||||
FROM shared_instance_versions
|
||||
WHERE id = $1
|
||||
",
|
||||
id as DBSharedInstanceVersionId,
|
||||
)
|
||||
.fetch_optional(exec)
|
||||
.await?;
|
||||
|
||||
Ok(result.map(Into::into))
|
||||
}
|
||||
|
||||
pub async fn get_for_instance(
|
||||
instance_id: DBSharedInstanceId,
|
||||
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||
) -> Result<Vec<Self>, sqlx::Error> {
|
||||
let results = sqlx::query_as!(
|
||||
SharedInstanceVersionQueryResult,
|
||||
"
|
||||
SELECT id, shared_instance_id, size, sha512, created
|
||||
FROM shared_instance_versions
|
||||
WHERE shared_instance_id = $1
|
||||
ORDER BY created DESC
|
||||
",
|
||||
instance_id as DBSharedInstanceId,
|
||||
)
|
||||
.fetch_all(exec)
|
||||
.await?;
|
||||
|
||||
Ok(results.into_iter().map(Into::into).collect())
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
@@ -631,19 +631,6 @@ impl DBUser {
|
||||
.await
|
||||
.wrap_err("failed to update versions author_id")?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE shared_instances
|
||||
SET owner_id = $1
|
||||
WHERE owner_id = $2
|
||||
",
|
||||
deleted_user as DBUserId,
|
||||
id as DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await
|
||||
.wrap_err("failed to update shared_instances owner_id")?;
|
||||
|
||||
use futures::TryStreamExt;
|
||||
let notifications: Vec<i64> = sqlx::query!(
|
||||
"
|
||||
@@ -1009,28 +996,6 @@ impl DBUser {
|
||||
.await
|
||||
.wrap_err("failed to delete oauth_client_authorizations")?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM shared_instance_users
|
||||
WHERE user_id = $1
|
||||
",
|
||||
id as DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await
|
||||
.wrap_err("failed to delete shared_instance_users")?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM shared_instance_invited_users
|
||||
WHERE invited_user_id = $1
|
||||
",
|
||||
id as DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await
|
||||
.wrap_err("failed to delete shared_instance_invited_users")?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE users_redeemals
|
||||
|
||||
@@ -18,7 +18,6 @@ pub use v3::payouts;
|
||||
pub use v3::projects;
|
||||
pub use v3::reports;
|
||||
pub use v3::sessions;
|
||||
pub use v3::shared_instances;
|
||||
pub use v3::teams;
|
||||
pub use v3::threads;
|
||||
pub use v3::users;
|
||||
|
||||
@@ -19,8 +19,6 @@ base62_id!(ProductPriceId);
|
||||
base62_id!(ProjectId);
|
||||
base62_id!(ReportId);
|
||||
base62_id!(SessionId);
|
||||
base62_id!(SharedInstanceId);
|
||||
base62_id!(SharedInstanceVersionId);
|
||||
base62_id!(TeamId);
|
||||
base62_id!(TeamMemberId);
|
||||
base62_id!(ThreadId);
|
||||
|
||||
@@ -15,7 +15,6 @@ pub mod payouts;
|
||||
pub mod projects;
|
||||
pub mod reports;
|
||||
pub mod sessions;
|
||||
pub mod shared_instances;
|
||||
pub mod teams;
|
||||
pub mod threads;
|
||||
pub mod user_limits;
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
use crate::bitflags_serde_impl;
|
||||
use crate::database::models::shared_instance_item::{
|
||||
DBSharedInstance, DBSharedInstanceUser, DBSharedInstanceVersion,
|
||||
};
|
||||
use crate::models::ids::{SharedInstanceId, SharedInstanceVersionId};
|
||||
use ariadne::ids::UserId;
|
||||
use bitflags::bitflags;
|
||||
use chrono::{DateTime, Utc};
|
||||
use hex::ToHex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SharedInstance {
|
||||
pub id: SharedInstanceId,
|
||||
pub title: String,
|
||||
pub owner: UserId,
|
||||
pub public: bool,
|
||||
pub current_version: Option<SharedInstanceVersion>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub additional_users: Option<Vec<SharedInstanceUser>>,
|
||||
}
|
||||
|
||||
impl SharedInstance {
|
||||
pub fn from_db(
|
||||
instance: DBSharedInstance,
|
||||
users: Option<Vec<DBSharedInstanceUser>>,
|
||||
current_version: Option<DBSharedInstanceVersion>,
|
||||
) -> Self {
|
||||
SharedInstance {
|
||||
id: instance.id.into(),
|
||||
title: instance.title,
|
||||
owner: instance.owner_id.into(),
|
||||
public: instance.public,
|
||||
current_version: current_version.map(Into::into),
|
||||
additional_users: users
|
||||
.map(|x| x.into_iter().map(Into::into).collect()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
|
||||
pub struct SharedInstanceVersion {
|
||||
pub id: SharedInstanceVersionId,
|
||||
pub shared_instance: SharedInstanceId,
|
||||
pub size: u64,
|
||||
pub sha512: String,
|
||||
pub created: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl From<DBSharedInstanceVersion> for SharedInstanceVersion {
|
||||
fn from(value: DBSharedInstanceVersion) -> Self {
|
||||
let version_id = value.id.into();
|
||||
let shared_instance_id = value.shared_instance_id.into();
|
||||
SharedInstanceVersion {
|
||||
id: version_id,
|
||||
shared_instance: shared_instance_id,
|
||||
size: value.size,
|
||||
sha512: value.sha512.encode_hex(),
|
||||
created: value.created,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct SharedInstanceUserPermissions: u64 {
|
||||
const EDIT = 1 << 0;
|
||||
const DELETE = 1 << 1;
|
||||
const UPLOAD_VERSION = 1 << 2;
|
||||
const DELETE_VERSION = 1 << 3;
|
||||
}
|
||||
}
|
||||
|
||||
bitflags_serde_impl!(SharedInstanceUserPermissions, u64);
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SharedInstanceUser {
|
||||
pub user: UserId,
|
||||
pub permissions: SharedInstanceUserPermissions,
|
||||
}
|
||||
|
||||
impl From<DBSharedInstanceUser> for SharedInstanceUser {
|
||||
fn from(user: DBSharedInstanceUser) -> Self {
|
||||
SharedInstanceUser {
|
||||
user: user.user_id.into(),
|
||||
permissions: user.permissions,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,6 @@ pub mod payouts;
|
||||
pub mod project_creation;
|
||||
pub mod projects;
|
||||
pub mod reports;
|
||||
pub mod shared_instance_version_creation;
|
||||
pub mod shared_instances;
|
||||
pub mod statistics;
|
||||
pub mod tags;
|
||||
pub mod teams;
|
||||
@@ -60,8 +58,6 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
.service(payouts::tremendous_webhook)
|
||||
.configure(projects::config)
|
||||
.configure(reports::config)
|
||||
.configure(shared_instance_version_creation::config)
|
||||
.configure(shared_instances::config)
|
||||
.configure(statistics::config)
|
||||
.configure(tags::config)
|
||||
.configure(teams::config)
|
||||
@@ -175,16 +171,6 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
reports::report_get_route,
|
||||
reports::report_edit_route,
|
||||
reports::report_delete_route,
|
||||
shared_instance_version_creation::shared_instance_version_create,
|
||||
shared_instances::shared_instance_create,
|
||||
shared_instances::shared_instance_list,
|
||||
shared_instances::shared_instance_get,
|
||||
shared_instances::shared_instance_edit,
|
||||
shared_instances::shared_instance_delete,
|
||||
shared_instances::shared_instance_version_list,
|
||||
shared_instances::shared_instance_version_get,
|
||||
shared_instances::shared_instance_version_delete,
|
||||
shared_instances::shared_instance_version_download,
|
||||
statistics::get_stats_route,
|
||||
tags::games_list_route,
|
||||
tags::category_list_route,
|
||||
|
||||
@@ -1,219 +0,0 @@
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database::models::shared_instance_item::{
|
||||
DBSharedInstance, DBSharedInstanceUser, DBSharedInstanceVersion,
|
||||
};
|
||||
use crate::database::models::{
|
||||
DBSharedInstanceId, DBSharedInstanceVersionId,
|
||||
generate_shared_instance_version_id,
|
||||
};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::database::{PgPool, PgTransaction};
|
||||
use crate::file_hosting::{FileHost, FileHostPublicity};
|
||||
use crate::models::ids::{SharedInstanceId, SharedInstanceVersionId};
|
||||
use crate::models::pats::Scopes;
|
||||
use crate::models::shared_instances::{
|
||||
SharedInstanceUserPermissions, SharedInstanceVersion,
|
||||
};
|
||||
use crate::queue::session::AuthQueue;
|
||||
use crate::routes::ApiError;
|
||||
use crate::routes::v3::project_creation::UploadedFile;
|
||||
use crate::util::ext::MRPACK_MIME_TYPE;
|
||||
use actix_web::http::header::ContentLength;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{HttpRequest, HttpResponse, post, web};
|
||||
use bytes::BytesMut;
|
||||
use chrono::Utc;
|
||||
use futures_util::StreamExt;
|
||||
use hex::FromHex;
|
||||
|
||||
const MAX_FILE_SIZE: usize = 500 * 1024 * 1024;
|
||||
const MAX_FILE_SIZE_TEXT: &str = "500 MB";
|
||||
|
||||
pub fn config(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
cfg.service(shared_instance_version_create);
|
||||
}
|
||||
|
||||
/// Create a shared instance version.
|
||||
#[utoipa::path(
|
||||
tag = "versions",
|
||||
post,
|
||||
params(
|
||||
("id" = SharedInstanceId, Path, description = "The ID of the shared instance")
|
||||
),
|
||||
request_body(content = Vec<u8>, content_type = "application/octet-stream"),
|
||||
responses(
|
||||
(status = 201, description = "Expected response to a valid request", body = SharedInstanceVersion),
|
||||
(status = 400, description = "Request was invalid, see given error"),
|
||||
(
|
||||
status = 401,
|
||||
description = "Incorrect token scopes or no authorization to access the requested item(s)"
|
||||
),
|
||||
(
|
||||
status = 404,
|
||||
description = "The requested item(s) were not found or no authorization to access the requested item(s)"
|
||||
)
|
||||
),
|
||||
security(("bearer_auth" = ["SHARED_INSTANCE_VERSION_CREATE"]))
|
||||
)]
|
||||
#[post("/shared-instance/{id}/version")]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn shared_instance_version_create(
|
||||
req: HttpRequest,
|
||||
pool: Data<PgPool>,
|
||||
payload: web::Payload,
|
||||
web::Header(ContentLength(content_length)): web::Header<ContentLength>,
|
||||
redis: Data<RedisPool>,
|
||||
file_host: Data<dyn FileHost>,
|
||||
info: web::Path<(SharedInstanceId,)>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
if content_length > MAX_FILE_SIZE {
|
||||
return Err(ApiError::InvalidInput(format!(
|
||||
"File size exceeds the maximum limit of {MAX_FILE_SIZE_TEXT}"
|
||||
)));
|
||||
}
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
let mut uploaded_files = vec![];
|
||||
|
||||
let result = shared_instance_version_create_inner(
|
||||
req,
|
||||
&pool,
|
||||
payload,
|
||||
content_length,
|
||||
&redis,
|
||||
&**file_host,
|
||||
info.into_inner().0.into(),
|
||||
&session_queue,
|
||||
&mut transaction,
|
||||
&mut uploaded_files,
|
||||
)
|
||||
.await;
|
||||
|
||||
if result.is_err() {
|
||||
let undo_result = super::project_creation::undo_uploads(
|
||||
&**file_host,
|
||||
&uploaded_files,
|
||||
)
|
||||
.await;
|
||||
let rollback_result = transaction.rollback().await;
|
||||
|
||||
undo_result?;
|
||||
if let Err(e) = rollback_result {
|
||||
return Err(e.into());
|
||||
}
|
||||
} else {
|
||||
transaction.commit().await?;
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn shared_instance_version_create_inner(
|
||||
req: HttpRequest,
|
||||
pool: &PgPool,
|
||||
mut payload: web::Payload,
|
||||
content_length: usize,
|
||||
redis: &RedisPool,
|
||||
file_host: &dyn FileHost,
|
||||
instance_id: DBSharedInstanceId,
|
||||
session_queue: &AuthQueue,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
uploaded_files: &mut Vec<UploadedFile>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
pool,
|
||||
redis,
|
||||
session_queue,
|
||||
Scopes::SHARED_INSTANCE_VERSION_CREATE,
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let Some(instance) = DBSharedInstance::get(instance_id, pool).await? else {
|
||||
return Err(ApiError::NotFound);
|
||||
};
|
||||
if !user.role.is_mod() && instance.owner_id != user.id.into() {
|
||||
let permissions = DBSharedInstanceUser::get_user_permissions(
|
||||
instance_id,
|
||||
user.id.into(),
|
||||
pool,
|
||||
)
|
||||
.await?;
|
||||
if let Some(permissions) = permissions {
|
||||
if !permissions
|
||||
.contains(SharedInstanceUserPermissions::UPLOAD_VERSION)
|
||||
{
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You do not have permission to upload a version for this shared instance.".to_string()
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
}
|
||||
|
||||
let version_id =
|
||||
generate_shared_instance_version_id(&mut *transaction).await?;
|
||||
|
||||
let mut file_data = BytesMut::new();
|
||||
while let Some(chunk) = payload.next().await {
|
||||
let chunk = chunk.map_err(|_| {
|
||||
ApiError::InvalidInput(
|
||||
"Unable to parse bytes in payload sent!".to_string(),
|
||||
)
|
||||
})?;
|
||||
|
||||
if file_data.len() + chunk.len() <= MAX_FILE_SIZE {
|
||||
file_data.extend_from_slice(&chunk);
|
||||
} else {
|
||||
file_data
|
||||
.extend_from_slice(&chunk[..MAX_FILE_SIZE - file_data.len()]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let file_data = file_data.freeze();
|
||||
let file_path = format!(
|
||||
"shared_instance/{}.mrpack",
|
||||
SharedInstanceVersionId::from(version_id),
|
||||
);
|
||||
|
||||
let upload_data = file_host
|
||||
.upload_file(
|
||||
MRPACK_MIME_TYPE,
|
||||
&file_path,
|
||||
FileHostPublicity::Private,
|
||||
file_data,
|
||||
)
|
||||
.await?;
|
||||
|
||||
uploaded_files.push(UploadedFile {
|
||||
name: file_path,
|
||||
publicity: upload_data.file_publicity,
|
||||
});
|
||||
|
||||
let sha512 = Vec::<u8>::from_hex(upload_data.content_sha512).unwrap();
|
||||
|
||||
let new_version = DBSharedInstanceVersion {
|
||||
id: version_id,
|
||||
shared_instance_id: instance_id,
|
||||
size: content_length as u64,
|
||||
sha512,
|
||||
created: Utc::now(),
|
||||
};
|
||||
new_version.insert(transaction).await?;
|
||||
|
||||
sqlx::query!(
|
||||
"UPDATE shared_instances SET current_version_id = $1 WHERE id = $2",
|
||||
new_version.id as DBSharedInstanceVersionId,
|
||||
instance_id as DBSharedInstanceId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
let version: SharedInstanceVersion = new_version.into();
|
||||
Ok(HttpResponse::Created().json(version))
|
||||
}
|
||||
@@ -1,628 +0,0 @@
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::auth::validate::get_maybe_user_from_headers;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::shared_instance_item::{
|
||||
DBSharedInstance, DBSharedInstanceUser, DBSharedInstanceVersion,
|
||||
};
|
||||
use crate::database::models::{
|
||||
DBSharedInstanceId, DBSharedInstanceVersionId, generate_shared_instance_id,
|
||||
};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::FileHost;
|
||||
use crate::models::ids::{SharedInstanceId, SharedInstanceVersionId};
|
||||
use crate::models::pats::Scopes;
|
||||
use crate::models::shared_instances::{
|
||||
SharedInstance, SharedInstanceUserPermissions, SharedInstanceVersion,
|
||||
};
|
||||
use crate::models::users::User;
|
||||
use crate::queue::session::AuthQueue;
|
||||
use crate::routes::ApiError;
|
||||
use crate::util::routes::read_typed_from_payload;
|
||||
use actix_web::web::{Data, Redirect};
|
||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
||||
use futures_util::future::try_join_all;
|
||||
use serde::Deserialize;
|
||||
use validator::Validate;
|
||||
|
||||
pub fn config(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
cfg.service(shared_instance_create)
|
||||
.service(shared_instance_list)
|
||||
.service(shared_instance_get)
|
||||
.service(shared_instance_edit)
|
||||
.service(shared_instance_delete)
|
||||
.service(shared_instance_version_list)
|
||||
.service(shared_instance_version_get)
|
||||
.service(shared_instance_version_delete)
|
||||
.service(shared_instance_version_download);
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Validate, utoipa::ToSchema)]
|
||||
pub struct CreateSharedInstance {
|
||||
#[validate(
|
||||
length(min = 3, max = 64),
|
||||
custom(function = "crate::util::validate::validate_name")
|
||||
)]
|
||||
pub title: String,
|
||||
#[serde(default)]
|
||||
pub public: bool,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
tag = "shared instances",
|
||||
request_body = CreateSharedInstance,
|
||||
responses((status = OK))
|
||||
)]
|
||||
#[post("/shared-instance")]
|
||||
pub async fn shared_instance_create(
|
||||
req: HttpRequest,
|
||||
pool: Data<PgPool>,
|
||||
mut body: web::Payload,
|
||||
redis: Data<RedisPool>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let new_instance: CreateSharedInstance =
|
||||
read_typed_from_payload(&mut body).await?;
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
&redis,
|
||||
&session_queue,
|
||||
Scopes::SHARED_INSTANCE_CREATE,
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let id = generate_shared_instance_id(&mut transaction).await?;
|
||||
|
||||
let instance = DBSharedInstance {
|
||||
id,
|
||||
title: new_instance.title,
|
||||
owner_id: user.id.into(),
|
||||
public: new_instance.public,
|
||||
current_version_id: None,
|
||||
};
|
||||
instance.insert(&mut transaction).await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
Ok(HttpResponse::Created().json(SharedInstance {
|
||||
id: id.into(),
|
||||
title: instance.title,
|
||||
owner: user.id,
|
||||
public: instance.public,
|
||||
current_version: None,
|
||||
additional_users: Some(vec![]),
|
||||
}))
|
||||
}
|
||||
|
||||
#[utoipa::path(tag = "shared instances", responses((status = OK)))]
|
||||
#[get("/shared-instance")]
|
||||
pub async fn shared_instance_list(
|
||||
req: HttpRequest,
|
||||
pool: Data<PgPool>,
|
||||
redis: Data<RedisPool>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
&redis,
|
||||
&session_queue,
|
||||
Scopes::SHARED_INSTANCE_READ,
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
|
||||
// TODO: Something for moderators to be able to see all instances?
|
||||
let instances =
|
||||
DBSharedInstance::list_for_user(user.id.into(), &**pool).await?;
|
||||
let instances = try_join_all(instances.into_iter().map(
|
||||
async |instance| -> Result<SharedInstance, ApiError> {
|
||||
let version = if let Some(version_id) = instance.current_version_id
|
||||
{
|
||||
DBSharedInstanceVersion::get(version_id, &**pool).await?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let instance_id = instance.id;
|
||||
Ok(SharedInstance::from_db(
|
||||
instance,
|
||||
Some(
|
||||
DBSharedInstanceUser::get_from_instance(
|
||||
instance_id,
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await?,
|
||||
),
|
||||
version,
|
||||
))
|
||||
},
|
||||
))
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(instances))
|
||||
}
|
||||
|
||||
#[utoipa::path(tag = "shared instances", responses((status = OK)))]
|
||||
#[get("/shared-instance/{id}")]
|
||||
pub async fn shared_instance_get(
|
||||
req: HttpRequest,
|
||||
pool: Data<PgPool>,
|
||||
redis: Data<RedisPool>,
|
||||
info: web::Path<(SharedInstanceId,)>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let id = info.into_inner().0.into();
|
||||
|
||||
let user = get_maybe_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
&redis,
|
||||
&session_queue,
|
||||
Scopes::SHARED_INSTANCE_READ,
|
||||
)
|
||||
.await?
|
||||
.map(|(_, user)| user);
|
||||
|
||||
let shared_instance = DBSharedInstance::get(id, &**pool).await?;
|
||||
|
||||
if let Some(shared_instance) = shared_instance {
|
||||
let users =
|
||||
DBSharedInstanceUser::get_from_instance(id, &**pool, &redis)
|
||||
.await?;
|
||||
|
||||
let privately_accessible = user.is_some_and(|user| {
|
||||
can_access_instance_privately(&shared_instance, &users, &user)
|
||||
});
|
||||
if !shared_instance.public && !privately_accessible {
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
|
||||
let current_version =
|
||||
if let Some(version_id) = shared_instance.current_version_id {
|
||||
DBSharedInstanceVersion::get(version_id, &**pool).await?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let shared_instance = SharedInstance::from_db(
|
||||
shared_instance,
|
||||
privately_accessible.then_some(users),
|
||||
current_version,
|
||||
);
|
||||
|
||||
Ok(HttpResponse::Ok().json(shared_instance))
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
fn can_access_instance_privately(
|
||||
instance: &DBSharedInstance,
|
||||
users: &[DBSharedInstanceUser],
|
||||
user: &User,
|
||||
) -> bool {
|
||||
user.role.is_mod()
|
||||
|| instance.owner_id == user.id.into()
|
||||
|| users.iter().any(|x| x.user_id == user.id.into())
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Validate, utoipa::ToSchema)]
|
||||
pub struct EditSharedInstance {
|
||||
#[validate(
|
||||
length(min = 3, max = 64),
|
||||
custom(function = "crate::util::validate::validate_name")
|
||||
)]
|
||||
pub title: Option<String>,
|
||||
pub public: Option<bool>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
tag = "shared instances",
|
||||
request_body = EditSharedInstance,
|
||||
responses((status = NO_CONTENT))
|
||||
)]
|
||||
#[patch("/shared-instance/{id}")]
|
||||
pub async fn shared_instance_edit(
|
||||
req: HttpRequest,
|
||||
pool: Data<PgPool>,
|
||||
mut body: web::Payload,
|
||||
redis: Data<RedisPool>,
|
||||
info: web::Path<(SharedInstanceId,)>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let id = info.into_inner().0.into();
|
||||
let edit_instance: EditSharedInstance =
|
||||
read_typed_from_payload(&mut body).await?;
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
&redis,
|
||||
&session_queue,
|
||||
Scopes::SHARED_INSTANCE_WRITE,
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let Some(instance) = DBSharedInstance::get(id, &**pool).await? else {
|
||||
return Err(ApiError::NotFound);
|
||||
};
|
||||
|
||||
if !user.role.is_mod() && instance.owner_id != user.id.into() {
|
||||
let permissions = DBSharedInstanceUser::get_user_permissions(
|
||||
id,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
if let Some(permissions) = permissions {
|
||||
if !permissions.contains(SharedInstanceUserPermissions::EDIT) {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You do not have permission to edit this shared instance."
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(title) = edit_instance.title {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE shared_instances
|
||||
SET title = $1
|
||||
WHERE id = $2
|
||||
",
|
||||
title,
|
||||
id as DBSharedInstanceId,
|
||||
)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(public) = edit_instance.public {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE shared_instances
|
||||
SET public = $1
|
||||
WHERE id = $2
|
||||
",
|
||||
public,
|
||||
id as DBSharedInstanceId,
|
||||
)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
}
|
||||
|
||||
#[utoipa::path(tag = "shared instances", responses((status = NO_CONTENT)))]
|
||||
#[delete("/shared-instance/{id}")]
|
||||
pub async fn shared_instance_delete(
|
||||
req: HttpRequest,
|
||||
pool: Data<PgPool>,
|
||||
redis: Data<RedisPool>,
|
||||
info: web::Path<(SharedInstanceId,)>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let id: DBSharedInstanceId = info.into_inner().0.into();
|
||||
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
&redis,
|
||||
&session_queue,
|
||||
Scopes::SHARED_INSTANCE_DELETE,
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let Some(instance) = DBSharedInstance::get(id, &**pool).await? else {
|
||||
return Err(ApiError::NotFound);
|
||||
};
|
||||
|
||||
if !user.role.is_mod() && instance.owner_id != user.id.into() {
|
||||
let permissions = DBSharedInstanceUser::get_user_permissions(
|
||||
id,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
if let Some(permissions) = permissions {
|
||||
if !permissions.contains(SharedInstanceUserPermissions::DELETE) {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You do not have permission to delete this shared instance.".to_string()
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM shared_instances
|
||||
WHERE id = $1
|
||||
",
|
||||
id as DBSharedInstanceId,
|
||||
)
|
||||
.execute(&**pool)
|
||||
.await?;
|
||||
|
||||
DBSharedInstanceUser::clear_cache(id, &redis).await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
}
|
||||
|
||||
#[utoipa::path(tag = "shared instances", responses((status = OK)))]
|
||||
#[get("/shared-instance/{id}/version")]
|
||||
pub async fn shared_instance_version_list(
|
||||
req: HttpRequest,
|
||||
pool: Data<PgPool>,
|
||||
redis: Data<RedisPool>,
|
||||
info: web::Path<(SharedInstanceId,)>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let id = info.into_inner().0.into();
|
||||
|
||||
let user = get_maybe_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
&redis,
|
||||
&session_queue,
|
||||
Scopes::SHARED_INSTANCE_READ,
|
||||
)
|
||||
.await?
|
||||
.map(|(_, user)| user);
|
||||
|
||||
let shared_instance = DBSharedInstance::get(id, &**pool).await?;
|
||||
|
||||
if let Some(shared_instance) = shared_instance {
|
||||
if !can_access_instance_as_maybe_user(
|
||||
&pool,
|
||||
&redis,
|
||||
&shared_instance,
|
||||
user,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
|
||||
let versions =
|
||||
DBSharedInstanceVersion::get_for_instance(id, &**pool).await?;
|
||||
let versions = versions
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<SharedInstanceVersion>>();
|
||||
|
||||
Ok(HttpResponse::Ok().json(versions))
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
#[utoipa::path(tag = "shared instances", responses((status = OK)))]
|
||||
#[get("/shared-instance-version/{id}")]
|
||||
pub async fn shared_instance_version_get(
|
||||
req: HttpRequest,
|
||||
pool: Data<PgPool>,
|
||||
redis: Data<RedisPool>,
|
||||
info: web::Path<(SharedInstanceVersionId,)>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let version_id = info.into_inner().0.into();
|
||||
|
||||
let user = get_maybe_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
&redis,
|
||||
&session_queue,
|
||||
Scopes::SHARED_INSTANCE_READ,
|
||||
)
|
||||
.await?
|
||||
.map(|(_, user)| user);
|
||||
|
||||
let version = DBSharedInstanceVersion::get(version_id, &**pool).await?;
|
||||
|
||||
if let Some(version) = version {
|
||||
let instance =
|
||||
DBSharedInstance::get(version.shared_instance_id, &**pool).await?;
|
||||
if let Some(instance) = instance {
|
||||
if !can_access_instance_as_maybe_user(
|
||||
&pool, &redis, &instance, user,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
|
||||
let version: SharedInstanceVersion = version.into();
|
||||
Ok(HttpResponse::Ok().json(version))
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
}
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
async fn can_access_instance_as_maybe_user(
|
||||
pool: &PgPool,
|
||||
redis: &RedisPool,
|
||||
instance: &DBSharedInstance,
|
||||
user: Option<User>,
|
||||
) -> Result<bool, ApiError> {
|
||||
if instance.public {
|
||||
return Ok(true);
|
||||
}
|
||||
let users =
|
||||
DBSharedInstanceUser::get_from_instance(instance.id, pool, redis)
|
||||
.await?;
|
||||
Ok(user.is_some_and(|user| {
|
||||
can_access_instance_privately(instance, &users, &user)
|
||||
}))
|
||||
}
|
||||
|
||||
#[utoipa::path(tag = "shared instances", responses((status = NO_CONTENT)))]
|
||||
#[delete("/shared-instance-version/{id}")]
|
||||
pub async fn shared_instance_version_delete(
|
||||
req: HttpRequest,
|
||||
pool: Data<PgPool>,
|
||||
redis: Data<RedisPool>,
|
||||
info: web::Path<(SharedInstanceVersionId,)>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let version_id = info.into_inner().0.into();
|
||||
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
&redis,
|
||||
&session_queue,
|
||||
Scopes::SHARED_INSTANCE_VERSION_DELETE,
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let shared_instance_version =
|
||||
DBSharedInstanceVersion::get(version_id, &**pool).await?;
|
||||
|
||||
if let Some(shared_instance_version) = shared_instance_version {
|
||||
let shared_instance = DBSharedInstance::get(
|
||||
shared_instance_version.shared_instance_id,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
if let Some(shared_instance) = shared_instance {
|
||||
if !user.role.is_mod() && shared_instance.owner_id != user.id.into()
|
||||
{
|
||||
let permissions = DBSharedInstanceUser::get_user_permissions(
|
||||
shared_instance.id,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
if let Some(permissions) = permissions {
|
||||
if !permissions
|
||||
.contains(SharedInstanceUserPermissions::DELETE)
|
||||
{
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You do not have permission to delete this shared instance version.".to_string()
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
}
|
||||
|
||||
delete_instance_version(shared_instance.id, version_id, &pool)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
}
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
async fn delete_instance_version(
|
||||
instance_id: DBSharedInstanceId,
|
||||
version_id: DBSharedInstanceVersionId,
|
||||
pool: &PgPool,
|
||||
) -> Result<(), ApiError> {
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM shared_instance_versions
|
||||
WHERE id = $1
|
||||
",
|
||||
version_id as DBSharedInstanceVersionId,
|
||||
)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE shared_instances
|
||||
SET current_version_id = (
|
||||
SELECT id FROM shared_instance_versions
|
||||
WHERE shared_instance_id = $1
|
||||
ORDER BY created DESC
|
||||
LIMIT 1
|
||||
)
|
||||
WHERE id = $1
|
||||
",
|
||||
instance_id as DBSharedInstanceId,
|
||||
)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[utoipa::path(tag = "shared instances", responses((status = TEMPORARY_REDIRECT)))]
|
||||
#[get("/shared-instance-version/{id}/download")]
|
||||
pub async fn shared_instance_version_download(
|
||||
req: HttpRequest,
|
||||
pool: Data<PgPool>,
|
||||
redis: Data<RedisPool>,
|
||||
file_host: Data<dyn FileHost>,
|
||||
info: web::Path<(SharedInstanceVersionId,)>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<Redirect, ApiError> {
|
||||
let version_id = info.into_inner().0.into();
|
||||
|
||||
let user = get_maybe_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
&redis,
|
||||
&session_queue,
|
||||
Scopes::SHARED_INSTANCE_VERSION_READ,
|
||||
)
|
||||
.await?
|
||||
.map(|(_, user)| user);
|
||||
|
||||
let version = DBSharedInstanceVersion::get(version_id, &**pool).await?;
|
||||
|
||||
if let Some(version) = version {
|
||||
let instance =
|
||||
DBSharedInstance::get(version.shared_instance_id, &**pool).await?;
|
||||
if let Some(instance) = instance {
|
||||
if !can_access_instance_as_maybe_user(
|
||||
&pool, &redis, &instance, user,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
|
||||
let file_name = format!(
|
||||
"shared_instance/{}.mrpack",
|
||||
SharedInstanceVersionId::from(version_id)
|
||||
);
|
||||
let url =
|
||||
file_host.get_url_for_private_file(&file_name, 180).await?;
|
||||
|
||||
Ok(Redirect::to(url).see_other())
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
}
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user