Compare commits
No commits in common. "3b4bb866ab8681dcc58aa9aaf837f9809de467e1" and "5530f397798e6b0f35bbf03d167e99ce93a09120" have entirely different histories.
3b4bb866ab
...
5530f39779
@ -68,9 +68,7 @@ impl MediaMetadata {
|
||||
|
||||
impl Database {
|
||||
pub async fn get_missing_media_metadata(&mut self) -> Result<Vec<FileUpload>> {
|
||||
let results: Vec<FileUpload> = sqlx::query_as("select * from uploads where \
|
||||
(mime_type like 'image/%' and (width is null or height is null)) or \
|
||||
(mime_type like 'video/%' and (width is null or height is null or bitrate is null or duration is null))")
|
||||
let results: Vec<FileUpload> = sqlx::query_as("select * from uploads where (width is null or height is null or bitrate is null or duration is null) and (mime_type like 'image/%' or mime_type like 'video/%')")
|
||||
.fetch_all(&self.pool)
|
||||
.await?;
|
||||
|
||||
|
@ -73,13 +73,7 @@ async fn main() -> Result<(), Error> {
|
||||
.attach(Shield::new()) // disable
|
||||
.mount(
|
||||
"/",
|
||||
routes![
|
||||
root,
|
||||
get_blob,
|
||||
head_blob,
|
||||
routes::void_cat_redirect,
|
||||
routes::void_cat_redirect_head
|
||||
],
|
||||
routes![root, get_blob, head_blob, routes::void_cat_redirect, routes::void_cat_redirect_head],
|
||||
)
|
||||
.mount("/admin", routes::admin_routes());
|
||||
|
||||
|
@ -25,7 +25,7 @@ pub struct BlobDescriptor {
|
||||
pub size: u64,
|
||||
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
|
||||
pub mime_type: Option<String>,
|
||||
pub uploaded: u64,
|
||||
pub created: u64,
|
||||
#[serde(rename = "nip94", skip_serializing_if = "Option::is_none")]
|
||||
pub nip94: Option<HashMap<String, String>>,
|
||||
}
|
||||
@ -45,7 +45,7 @@ impl BlobDescriptor {
|
||||
sha256: id_hex,
|
||||
size: value.size,
|
||||
mime_type: Some(value.mime_type.clone()),
|
||||
uploaded: value.created.timestamp() as u64,
|
||||
created: value.created.timestamp() as u64,
|
||||
nip94: Some(
|
||||
Nip94Event::from_upload(settings, value)
|
||||
.tags
|
||||
|
@ -59,27 +59,22 @@ struct PagedResult<T> {
|
||||
impl Nip94Event {
|
||||
pub fn from_upload(settings: &Settings, upload: &FileUpload) -> Self {
|
||||
let hex_id = hex::encode(&upload.id);
|
||||
let ext = if upload.mime_type != "application/octet-stream" {
|
||||
mime2ext::mime2ext(&upload.mime_type)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut tags = vec![
|
||||
vec![
|
||||
"url".to_string(),
|
||||
format!("{}/{}.{}", &settings.public_url, &hex_id, ext.unwrap_or("")),
|
||||
format!(
|
||||
"{}/{}{}",
|
||||
&settings.public_url,
|
||||
&hex_id,
|
||||
mime2ext::mime2ext(&upload.mime_type)
|
||||
.map(|m| format!(".{m}"))
|
||||
.unwrap_or("".to_string())
|
||||
),
|
||||
],
|
||||
vec!["x".to_string(), hex_id.clone()],
|
||||
vec!["x".to_string(), hex_id],
|
||||
vec!["m".to_string(), upload.mime_type.clone()],
|
||||
vec!["size".to_string(), upload.size.to_string()],
|
||||
];
|
||||
if upload.mime_type.starts_with("image/") || upload.mime_type.starts_with("video/") {
|
||||
tags.push(vec![
|
||||
"thumb".to_string(),
|
||||
format!("{}/thumb/{}.webp", &settings.public_url, &hex_id),
|
||||
]);
|
||||
}
|
||||
|
||||
if let Some(bh) = &upload.blur_hash {
|
||||
tags.push(vec!["blurhash".to_string(), bh.clone()]);
|
||||
}
|
||||
@ -407,10 +402,6 @@ pub async fn get_blob_thumb(
|
||||
return Err(Status::NotFound);
|
||||
};
|
||||
|
||||
if !(info.mime_type.starts_with("image/") || info.mime_type.starts_with("video/")) {
|
||||
return Err(Status::NotFound);
|
||||
}
|
||||
|
||||
let file_path = fs.get(&id);
|
||||
|
||||
let mut thumb_file = temp_dir().join(format!("thumb_{}", sha256));
|
||||
@ -446,15 +437,10 @@ pub async fn void_cat_redirect(id: &str, settings: &State<Settings>) -> Option<N
|
||||
id
|
||||
};
|
||||
if let Some(base) = &settings.void_cat_files {
|
||||
let uuid = if let Ok(b58) = nostr::bitcoin::base58::decode(id) {
|
||||
uuid::Uuid::from_slice_le(b58.as_slice())
|
||||
} else {
|
||||
uuid::Uuid::parse_str(id)
|
||||
};
|
||||
if uuid.is_err() {
|
||||
return None;
|
||||
}
|
||||
let f = base.join(VoidFile::map_to_path(&uuid.unwrap()));
|
||||
let uuid =
|
||||
uuid::Uuid::from_slice_le(nostr::bitcoin::base58::decode(id).unwrap().as_slice())
|
||||
.unwrap();
|
||||
let f = base.join(VoidFile::map_to_path(&uuid));
|
||||
debug!("Legacy file map: {} => {}", id, f.display());
|
||||
if let Ok(f) = NamedFile::open(f).await {
|
||||
Some(f)
|
||||
|
@ -22,9 +22,9 @@ export class Route96 {
|
||||
return data;
|
||||
}
|
||||
|
||||
async listFiles(page = 0, count = 10, mime: string | undefined) {
|
||||
async listFiles(page = 0, count = 10) {
|
||||
const rsp = await this.#req(
|
||||
`admin/files?page=${page}&count=${count}${mime ? `&mime_type=${mime}` : ""}`,
|
||||
`admin/files?page=${page}&count=${count}`,
|
||||
"GET",
|
||||
);
|
||||
const data = await this.#handleResponse<AdminResponseFileList>(rsp);
|
||||
|
@ -23,7 +23,6 @@ export default function Upload() {
|
||||
const [adminListedFiles, setAdminListedFiles] = useState<Nip96FileList>();
|
||||
const [listedPage, setListedPage] = useState(0);
|
||||
const [adminListedPage, setAdminListedPage] = useState(0);
|
||||
const [mimeFilter, setMimeFilter] = useState<string>();
|
||||
|
||||
const login = useLogin();
|
||||
const pub = usePublisher();
|
||||
@ -86,7 +85,7 @@ export default function Upload() {
|
||||
try {
|
||||
setError(undefined);
|
||||
const uploader = new Route96(url, pub);
|
||||
const result = await uploader.listFiles(n, 50, mimeFilter);
|
||||
const result = await uploader.listFiles(n, 50);
|
||||
setAdminListedFiles(result);
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
@ -136,7 +135,7 @@ export default function Upload() {
|
||||
|
||||
useEffect(() => {
|
||||
listAllUploads(adminListedPage);
|
||||
}, [adminListedPage, mimeFilter]);
|
||||
}, [adminListedPage]);
|
||||
|
||||
useEffect(() => {
|
||||
if (pub && !self) {
|
||||
@ -250,18 +249,6 @@ export default function Upload() {
|
||||
<hr />
|
||||
<h3>Admin File List:</h3>
|
||||
<Button onClick={() => listAllUploads(0)}>List All Uploads</Button>
|
||||
<div>
|
||||
<select value={mimeFilter} onChange={e => setMimeFilter(e.target.value)}>
|
||||
<option value={""}>All</option>
|
||||
<option>image/webp</option>
|
||||
<option>image/jpeg</option>
|
||||
<option>image/jpg</option>
|
||||
<option>image/png</option>
|
||||
<option>image/gif</option>
|
||||
<option>video/mp4</option>
|
||||
<option>video/mov</option>
|
||||
</select>
|
||||
</div>
|
||||
{adminListedFiles && (
|
||||
<FileList
|
||||
files={adminListedFiles.files}
|
||||
|
Loading…
x
Reference in New Issue
Block a user