{"record":{"id":"800c64fedd8a26b3","repo":"BigPizzaV3/CodexPlusPlus","slug":"manifest-files-mediatype","errorCode":null,"errorMessage":"manifest.files 的 mediaType 不匹配：{}","messagePattern":"manifest\\.files 的 mediaType 不匹配：(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_package.rs","lineNumber":1129,"sourceCode":"            \"manifest.json\" => manifest_bytes,\n            \"theme.json\" => theme_bytes,\n            \"theme.css\" => css_bytes,\n            path if path == image_name => image_bytes,\n            \"LICENSE.txt\" => license_bytes.context(\"manifest 声明了 LICENSE.txt 但包内缺失\")?,\n            \"manifest.sig\" => continue,\n            _ => continue,\n        };\n        let expected_media_type = match file.path.as_str() {\n            \"theme.json\" => \"application/json\",\n            \"theme.css\" => \"text/css\",\n            \"background.webp\" => \"image/webp\",\n            \"background.jpg\" => \"image/jpeg\",\n            \"background.png\" => \"image/png\",\n            \"LICENSE.txt\" => \"text/plain\",\n            _ => \"\",\n        };\n        if file.media_type != expected_media_type {\n            bail!(\"manifest.files 的 mediaType 不匹配：{}\", file.path);\n        }\n        let actual = format!(\"{:x}\", Sha256::digest(bytes));\n        if file.bytes != bytes.len() || !actual.eq_ignore_ascii_case(&file.sha256) {\n            bail!(\"manifest.files 的 SHA-256 或大小不匹配：{}\", file.path);\n        }\n    }\n    if !seen.contains(\"theme.json\") || !seen.contains(\"theme.css\") || !seen.contains(image_name) {\n        bail!(\"manifest.files 缺少必需文件\");\n    }\n    if seen.contains(\"LICENSE.txt\") != license_bytes.is_some() {\n        bail!(\"manifest.files 的 LICENSE.txt 与包内容不一致\");\n    }\n    Ok(())\n}\n\nfn valid_theme_id(value: &str) -> bool {\n    let mut chars = value.chars();\n    chars.next().is_some_and(|c| c.is_ascii_alphanumeric())","sourceCodeStart":1111,"sourceCodeEnd":1147,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_package.rs#L1111-L1147","documentation":"For each manifest.files entry, validate_manifest_files derives the expected media type from the file path (theme.json -> application/json, theme.css -> text/css, background.webp/jpg/png -> image/webp|jpeg|png, LICENSE.txt -> text/plain) and requires the declared mediaType to match exactly. A mismatch throws this error naming the file.","triggerScenarios":"Calling validate_and_read_package where a files entry declares a mediaType that does not equal the value derived from its path — e.g. theme.css declared as application/json, background.jpg declared as image/png, or a wrong/missing/extra mediaType on any entry.","commonSituations":"Hand-editing mediaType fields; using generic application/octet-stream for images; switching the background from .jpg to .png without updating mediaType; copying entries between files without adjusting the type.","solutions":["Set each entry's mediaType to the value implied by its path (theme.json: application/json; theme.css: text/css; background.webp: image/webp; background.jpg: image/jpeg; background.png: image/png; LICENSE.txt: text/plain)","Update mediaType whenever you rename or swap the background image extension","Regenerate the manifest with the packaging tool so media types are computed automatically"],"exampleFix":"// before\n{ \"path\": \"background.jpg\", \"mediaType\": \"image/png\", ... }\n// after\n{ \"path\": \"background.jpg\", \"mediaType\": \"image/jpeg\", ... }","handlingStrategy":"validation","validationCode":"const MIME = { \"theme.json\":\"application/json\", \"theme.css\":\"text/css\", \"background.webp\":\"image/webp\", \"background.jpg\":\"image/jpeg\", \"background.png\":\"image/png\", \"LICENSE.txt\":\"text/plain\" };\nfor (const f of manifest.files) {\n  if (f.path in MIME && f.mediaType !== MIME[f.path]) {\n    throw new Error(`${f.path}: mediaType must be ${MIME[f.path]}`);\n  }\n}","typeGuard":"function hasMatchingMediaType(f) {\n  const MIME = { \"theme.json\":\"application/json\", \"theme.css\":\"text/css\", \"background.webp\":\"image/webp\", \"background.jpg\":\"image/jpeg\", \"background.png\":\"image/png\", \"LICENSE.txt\":\"text/plain\" };\n  return !(f.path in MIME) || f.mediaType === MIME[f.path];\n}","tryCatchPattern":null,"preventionTips":["Derive mediaType from the file extension with a lookup table, never by hand","Update mediaType whenever the background image format changes","Keep the packaging tool as the single writer of manifest.json"],"tags":["validation","manifest","mime-type","skin-package"],"backgroundTag":"type-mismatch","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}