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