Only list images for possible covers

This commit is contained in:
Baptiste Gelez 2018-10-31 14:40:31 +01:00
parent f593ce40af
commit 25b7399e7f
2 changed files with 11 additions and 5 deletions

View File

@ -44,28 +44,32 @@ impl Media {
pub fn to_json(&self, conn: &Connection) -> serde_json::Value { pub fn to_json(&self, conn: &Connection) -> serde_json::Value {
let mut json = serde_json::to_value(self).expect("Media::to_json: serialization error"); let mut json = serde_json::to_value(self).expect("Media::to_json: serialization error");
let url = self.url(conn); let url = self.url(conn);
let (preview, html, md) = match self.file_path.rsplitn(2, '.').next().expect("Media::to_json: extension error") { let (cat, preview, html, md) = match self.file_path.rsplitn(2, '.').next().expect("Media::to_json: extension error") {
"png" | "jpg" | "jpeg" | "gif" | "svg" => ( "png" | "jpg" | "jpeg" | "gif" | "svg" => (
"image",
format!("<img src=\"{}\" alt=\"{}\" title=\"{}\" class=\"preview\">", url, self.alt_text, self.alt_text), format!("<img src=\"{}\" alt=\"{}\" title=\"{}\" class=\"preview\">", url, self.alt_text, self.alt_text),
format!("<img src=\"{}\" alt=\"{}\" title=\"{}\">", url, self.alt_text, self.alt_text), format!("<img src=\"{}\" alt=\"{}\" title=\"{}\">", url, self.alt_text, self.alt_text),
format!("![{}]({})", self.alt_text, url), format!("![{}]({})", self.alt_text, url),
), ),
"mp3" | "wav" | "flac" => ( "mp3" | "wav" | "flac" => (
"audio",
format!("<audio src=\"{}\" title=\"{}\" class=\"preview\"></audio>", url, self.alt_text), format!("<audio src=\"{}\" title=\"{}\" class=\"preview\"></audio>", url, self.alt_text),
format!("<audio src=\"{}\" title=\"{}\"></audio>", url, self.alt_text), format!("<audio src=\"{}\" title=\"{}\"></audio>", url, self.alt_text),
format!("<audio src=\"{}\" title=\"{}\"></audio>", url, self.alt_text), format!("<audio src=\"{}\" title=\"{}\"></audio>", url, self.alt_text),
), ),
"mp4" | "avi" | "webm" | "mov" => ( "mp4" | "avi" | "webm" | "mov" => (
"video",
format!("<video src=\"{}\" title=\"{}\" class=\"preview\"></video>", url, self.alt_text), format!("<video src=\"{}\" title=\"{}\" class=\"preview\"></video>", url, self.alt_text),
format!("<video src=\"{}\" title=\"{}\"></video>", url, self.alt_text), format!("<video src=\"{}\" title=\"{}\"></video>", url, self.alt_text),
format!("<video src=\"{}\" title=\"{}\"></video>", url, self.alt_text), format!("<video src=\"{}\" title=\"{}\"></video>", url, self.alt_text),
), ),
_ => (String::new(), String::new(), String::new()) _ => ("unknown", String::new(), String::new(), String::new())
}; };
json["html_preview"] = json!(preview); json["html_preview"] = json!(preview);
json["html"] = json!(html); json["html"] = json!(html);
json["url"] = json!(url); json["url"] = json!(url);
json["md"] = json!(md); json["md"] = json!(md);
json["category"] = json!(cat);
json json
} }

View File

@ -39,9 +39,11 @@
<select id="cover" name="cover"> <select id="cover" name="cover">
<option value="none" {% if form is undefined or form.cover is undefined %}selected{% endif %}>{{ "None" | _ }}</option> <option value="none" {% if form is undefined or form.cover is undefined %}selected{% endif %}>{{ "None" | _ }}</option>
{% for media in medias %} {% for media in medias %}
<option value="{{ media.id }}" {% if form is defined and form.cover is defined and form.cover == media.id %}selected{% endif %}> {% if media.category == "image" %}
{{ media.alt_text | default(value=media.content_warning) }} <option value="{{ media.id }}" {% if form is defined and form.cover is defined and form.cover == media.id %}selected{% endif %}>
</option> {{ media.alt_text | default(value=media.content_warning) }}
</option>
{% endif %}
{% endfor %} {% endfor %}
</select> </select>