1
0

Add files to initial versions/mods (#84)

* Add files to initial versions/mods

* Remove useless code, fix actual problem

* Remove debug text

* Rename body to description
This commit is contained in:
Geometrically
2020-10-19 22:08:47 -07:00
committed by GitHub
parent 8e1f1ff2e6
commit b05b38b269
3 changed files with 15 additions and 14 deletions

View File

@@ -86,7 +86,7 @@ impl VersionBuilder {
version.insert(&mut *transaction).await?;
for file in self.files {
file.insert(self.version_id, transaction);
file.insert(self.version_id, transaction).await?;
}
for dependency in self.dependencies {

View File

@@ -352,7 +352,6 @@ async fn mod_create_inner(
process_icon_upload(
uploaded_files,
mod_id,
file_name,
file_extension,
file_host,
field,
@@ -414,7 +413,7 @@ async fn mod_create_inner(
// Upload the mod desciption markdown to the CDN
// TODO: Should we also process and upload an html version here for SSR?
let body_path = format!("data/{}/body.md", mod_id);
let body_path = format!("data/{}/description.md", mod_id);
{
let upload_data = file_host
.upload_file(
@@ -547,7 +546,10 @@ async fn create_initial_version(
// Upload the version's changelog to the CDN
let changelog_path = if let Some(changelog) = &version_data.version_body {
let changelog_path = format!("data/{}/changelogs/{}/body.md", mod_id, version_id);
let changelog_path = format!(
"data/{}/versions/{}/changelog.md",
mod_id, version_data.version_number
);
let uploaded_text = file_host
.upload_file(
@@ -613,7 +615,6 @@ async fn create_initial_version(
async fn process_icon_upload(
uploaded_files: &mut Vec<UploadedFile>,
mod_id: ModId,
file_name: &str,
file_extension: &str,
file_host: &dyn FileHost,
mut field: actix_multipart::Field,
@@ -625,22 +626,22 @@ async fn process_icon_upload(
data.extend_from_slice(&chunk.map_err(CreateError::MultipartError)?);
}
if data.len() >= 16384 {
if data.len() >= 262144 {
return Err(CreateError::InvalidInput(String::from(
"Icons must be smaller than 16KiB",
"Icons must be smaller than 256KiB",
)));
}
let upload_data = file_host
.upload_file(
content_type,
&format!("mods/icons/{}/{}", mod_id, file_name),
&format!("data/{}/icon.{}", mod_id, file_extension),
data,
)
.await?;
uploaded_files.push(UploadedFile {
file_id: upload_data.file_id.clone(),
file_id: upload_data.file_id,
file_name: upload_data.file_name.clone(),
});

View File

@@ -209,9 +209,9 @@ async fn version_create_inner(
if let Some(body) = &version_create_data.version_body {
let path = format!(
"data/{}/changelogs/{}/body.md",
"data/{}/versions/{}/changelog.md",
version_create_data.mod_id.unwrap(),
version_id
version_create_data.version_number
);
let uploaded_text = file_host
@@ -219,7 +219,7 @@ async fn version_create_inner(
.await?;
uploaded_files.push(UploadedFile {
file_id: uploaded_text.file_id.clone(),
file_id: uploaded_text.file_id,
file_name: uploaded_text.file_name.clone(),
});
body_path = Some(path);
@@ -509,13 +509,13 @@ pub async fn upload_file(
let upload_data = file_host
.upload_file(
content_type,
&format!("{}/{}/{}", mod_id, version_number, file_name),
&format!("data/{}/versions/{}/{}", mod_id, version_number, file_name),
data.to_vec(),
)
.await?;
uploaded_files.push(UploadedFile {
file_id: upload_data.file_id.clone(),
file_id: upload_data.file_id,
file_name: upload_data.file_name.clone(),
});