Skip to content

Commit

Permalink
Check thumbnail
Browse files Browse the repository at this point in the history
Fix #7
  • Loading branch information
elegaanz committed May 27, 2024
1 parent db66d2e commit f9135d9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/check/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub async fn check(
};

dont_exclude_template_files(diags, &manifest, package_dir, exclude);
check_thumbnail(diags, &manifest, manifest_file_id, package_dir);

Worlds {
package: world,
Expand Down Expand Up @@ -482,3 +483,34 @@ fn dont_exclude_template_files(

Some(())
}

fn check_thumbnail(
diags: &mut Diagnostics,
manifest: &toml_edit::ImDocument<&String>,
manifest_file_id: FileId,
package_dir: &Path,
) -> Option<()> {
let thumbnail = manifest.get("template")?.as_table()?.get("thumbnail")?;
let thumbnail_path = package_dir.join(thumbnail.as_str()?);

if !thumbnail_path.exists() {
diags.emit(
Diagnostic::error()
.with_labels(vec![Label::primary(manifest_file_id, thumbnail.span()?)])
.with_message("This file does not exist."),
)
}

if !matches!(
thumbnail_path.extension().and_then(|e| e.to_str()),
Some("png" | "webp")
) {
diags.emit(
Diagnostic::error()
.with_labels(vec![Label::primary(manifest_file_id, thumbnail.span()?)])
.with_message("Thumbnails should be PNG or WebP files."),
)
}

Some(())
}

0 comments on commit f9135d9

Please sign in to comment.