Allow using Multiple Boss App IDs for WUP Files
This commit is contained in:
parent
3b6c3b92ba
commit
f6897c30ac
9 changed files with 52 additions and 48 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT\n deleted,\n file_key,\n data_id,\n task_id,\n boss_app_id,\n supported_countries,\n supported_languages,\n attributes AS \"attributes!: Json<FileWUPAttributes>\",\n creator_user,\n name,\n type,\n hash,\n size,\n notify_on_new,\n notify_led,\n condition_played,\n auto_delete,\n created,\n updated\n FROM files_wup WHERE data_id = $1 AND deleted = false;",
|
||||
"query": "SELECT\n deleted,\n file_key,\n data_id,\n task_id,\n boss_app_ids,\n supported_countries,\n supported_languages,\n attributes AS \"attributes!: Json<FileWUPAttributes>\",\n creator_user,\n name,\n type,\n hash,\n size,\n notify_on_new,\n notify_led,\n condition_played,\n auto_delete,\n created,\n updated\n FROM files_wup WHERE data_id = $1 AND deleted = false;",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
|
|
@ -25,8 +25,8 @@
|
|||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "boss_app_id",
|
||||
"type_info": "Text"
|
||||
"name": "boss_app_ids",
|
||||
"type_info": "TextArray"
|
||||
},
|
||||
{
|
||||
"ordinal": 5,
|
||||
|
|
@ -126,5 +126,5 @@
|
|||
false
|
||||
]
|
||||
},
|
||||
"hash": "3cc1241465c9bb03d570502f8ef4d8492b868f5ea0936d5e820057d7e3d3db06"
|
||||
"hash": "3f94c60b037a9d97159ac0eecf6a7aa2d024212b69e7bb5e1a88ad71fd2fb9fa"
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n INSERT INTO files_wup (\n file_key,\n task_id,\n boss_app_id,\n supported_countries,\n supported_languages,\n attributes,\n creator_user,\n name,\n type,\n hash,\n size,\n notify_on_new,\n notify_led,\n condition_played,\n auto_delete,\n created,\n updated\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15,\n NOW() AT TIME ZONE 'UTC',\n NOW() AT TIME ZONE 'UTC'\n )\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text",
|
||||
"Text",
|
||||
"TextArray",
|
||||
"TextArray",
|
||||
"Jsonb",
|
||||
"Text",
|
||||
"Text",
|
||||
"Text",
|
||||
"Text",
|
||||
"Int8",
|
||||
"TextArray",
|
||||
"Bool",
|
||||
"Int8",
|
||||
"Bool"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "42f96f5890db3be1b4fafd30cfc3fff9163933840cc9c5cbb5dd2b4ac933473d"
|
||||
}
|
||||
28
.sqlx/query-696db3dcba46ed502e8714b71c78735a64bab16b7c5c08d7667faf673bbaf5c8.json
generated
Normal file
28
.sqlx/query-696db3dcba46ed502e8714b71c78735a64bab16b7c5c08d7667faf673bbaf5c8.json
generated
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n INSERT INTO files_wup (\n file_key,\n task_id,\n boss_app_ids,\n supported_countries,\n supported_languages,\n attributes,\n creator_user,\n name,\n type,\n hash,\n size,\n notify_on_new,\n notify_led,\n condition_played,\n auto_delete,\n created,\n updated\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15,\n NOW() AT TIME ZONE 'UTC',\n NOW() AT TIME ZONE 'UTC'\n )\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text",
|
||||
"TextArray",
|
||||
"TextArray",
|
||||
"TextArray",
|
||||
"Jsonb",
|
||||
"Text",
|
||||
"Text",
|
||||
"Text",
|
||||
"Text",
|
||||
"Int8",
|
||||
"TextArray",
|
||||
"Bool",
|
||||
"Int8",
|
||||
"Bool"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "696db3dcba46ed502e8714b71c78735a64bab16b7c5c08d7667faf673bbaf5c8"
|
||||
}
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE files_wup\n SET deleted = TRUE,\n updated = NOW() AT TIME ZONE 'UTC'\n WHERE boss_app_id = $1 AND task_id = $2 AND name = $3;\n ",
|
||||
"query": "\n UPDATE files_wup\n SET deleted = TRUE,\n updated = NOW() AT TIME ZONE 'UTC'\n WHERE boss_app_ids = $1 AND task_id = $2 AND name = $3;\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"TextArray",
|
||||
"Text",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "84520448fbf405540d5ea250c97ff57963a3164b200c42955f1d787de8f62161"
|
||||
"hash": "a9144c26b98e762fa510d8202648352614d0685d98e97d2e4c0cd20425a74632"
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ CREATE TABLE files_wup (
|
|||
data_id BIGINT PRIMARY KEY DEFAULT nextval('files_wup_data_id_seq'),
|
||||
file_key TEXT NOT NULL,
|
||||
task_id TEXT NOT NULL,
|
||||
boss_app_id TEXT NOT NULL,
|
||||
boss_app_ids TEXT[] NOT NULL,
|
||||
supported_countries TEXT[] NOT NULL,
|
||||
supported_languages TEXT[] NOT NULL,
|
||||
attributes JSONB NOT NULL,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::{crypto::wiiu::encrypt_wiiu, models::file_wup::FileWUPAttributes};
|
|||
#[derive(Deserialize)]
|
||||
pub struct UploadedWUP {
|
||||
task_id: String,
|
||||
boss_app_id: String,
|
||||
boss_app_ids: Vec<String>,
|
||||
supported_countries: Vec<String>,
|
||||
supported_languages: Vec<String>,
|
||||
name: Option<String>,
|
||||
|
|
@ -54,7 +54,8 @@ pub async fn upload_file_wup(pool: &State<Pool>, input: Json<UploadedWUP>, auth:
|
|||
if data.name == None && !data.name_equals_data_id { return Err(Status::BadRequest) };
|
||||
let name = data.name.clone().unwrap();
|
||||
|
||||
if data.boss_app_id.len() != 16 { return Err(Status::BadRequest) };
|
||||
for id in &data.boss_app_ids { if id.len() != 16 { return Err(Status::BadRequest); }; };
|
||||
//if data.boss_app_id.len() != 16 { return Err(Status::BadRequest) };
|
||||
|
||||
if !is_valid_countries(&data.supported_countries) { return Err(Status::BadRequest) };
|
||||
if !is_valid_languages(&data.supported_languages) { return Err(Status::BadRequest) };
|
||||
|
|
@ -94,7 +95,8 @@ pub async fn upload_file_wup(pool: &State<Pool>, input: Json<UploadedWUP>, auth:
|
|||
let hash_bytes = &hasher.finalize()[..];
|
||||
let hash = hex::encode(hash_bytes);
|
||||
|
||||
let file_key = format!("{}/{}/{}", data.boss_app_id, data.task_id, hash);
|
||||
//let file_key = format!("{}/{}/{}", data.boss_app_id, data.task_id, hash);
|
||||
let file_key = format!("{}/{}", data.task_id, hash);
|
||||
|
||||
let _ = sqlx::query!(
|
||||
r#"
|
||||
|
|
@ -117,9 +119,9 @@ pub async fn upload_file_wup(pool: &State<Pool>, input: Json<UploadedWUP>, auth:
|
|||
UPDATE files_wup
|
||||
SET deleted = TRUE,
|
||||
updated = NOW() AT TIME ZONE 'UTC'
|
||||
WHERE boss_app_id = $1 AND task_id = $2 AND name = $3;
|
||||
WHERE boss_app_ids = $1 AND task_id = $2 AND name = $3;
|
||||
"#,
|
||||
&data.boss_app_id,
|
||||
&data.boss_app_ids,
|
||||
&data.task_id,
|
||||
name
|
||||
)
|
||||
|
|
@ -142,7 +144,7 @@ pub async fn upload_file_wup(pool: &State<Pool>, input: Json<UploadedWUP>, auth:
|
|||
INSERT INTO files_wup (
|
||||
file_key,
|
||||
task_id,
|
||||
boss_app_id,
|
||||
boss_app_ids,
|
||||
supported_countries,
|
||||
supported_languages,
|
||||
attributes,
|
||||
|
|
@ -165,7 +167,7 @@ pub async fn upload_file_wup(pool: &State<Pool>, input: Json<UploadedWUP>, auth:
|
|||
"#,
|
||||
file_key,
|
||||
data.task_id,
|
||||
data.boss_app_id,
|
||||
&data.boss_app_ids,
|
||||
&data.supported_countries,
|
||||
&data.supported_languages,
|
||||
attributes,
|
||||
|
|
|
|||
|
|
@ -59,8 +59,9 @@ pub async fn get_wup_task_files(
|
|||
|
||||
if !allow_deleted { qb.push(" AND deleted = false"); };
|
||||
|
||||
qb.push(" AND boss_app_id = ");
|
||||
qb.push(" AND boss_app_ids @> ARRAY[");
|
||||
qb.push_bind(boss_app_id);
|
||||
qb.push("]");
|
||||
|
||||
qb.push(" AND task_id = ");
|
||||
qb.push_bind(task_id);
|
||||
|
|
@ -110,8 +111,9 @@ pub async fn get_wup_task_file(
|
|||
|
||||
if !allow_deleted { qb.push(" AND deleted = false"); };
|
||||
|
||||
qb.push(" AND boss_app_id = ");
|
||||
qb.push(" AND boss_app_ids @> ARRAY[");
|
||||
qb.push_bind(boss_app_id);
|
||||
qb.push("]");
|
||||
|
||||
qb.push(" AND task_id = ");
|
||||
qb.push_bind(&task_id[..7]);
|
||||
|
|
@ -150,7 +152,7 @@ pub async fn get_wup_task_file_by_data_id(pool: &Pool, data_id: i64) -> Option<F
|
|||
file_key,
|
||||
data_id,
|
||||
task_id,
|
||||
boss_app_id,
|
||||
boss_app_ids,
|
||||
supported_countries,
|
||||
supported_languages,
|
||||
attributes AS "attributes!: Json<FileWUPAttributes>",
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ pub struct FileWUP {
|
|||
pub file_key: String,
|
||||
pub data_id: Option<i64>,
|
||||
pub task_id: String,
|
||||
pub boss_app_id: String,
|
||||
pub boss_app_ids: Vec<String>,
|
||||
pub supported_countries: Vec<String>,
|
||||
pub supported_languages: Vec<String>,
|
||||
pub attributes: Json<FileWUPAttributes>,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ pub async fn data(pool: &State<Pool>, boss_app_id: String, data_id: i64, file_ha
|
|||
None => return Err(Status::NotFound),
|
||||
};
|
||||
|
||||
if file_wup.hash != file_hash || file_wup.boss_app_id != boss_app_id { return Err(Status::NotFound); }
|
||||
if file_wup.hash != file_hash || !file_wup.boss_app_ids.contains(&boss_app_id) { return Err(Status::NotFound); }
|
||||
|
||||
let file = sqlx::query_scalar!(
|
||||
"SELECT data FROM files WHERE key = $1",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue