[+] Static

This commit is contained in:
2025-10-26 19:32:03 +08:00
parent 3cf43e18c3
commit 1db5830a70
4 changed files with 14 additions and 23 deletions
@@ -3,10 +3,12 @@ package aza.instant
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import aza.instant.network.BackendClient
import io.ktor.client.call.body
import java.io.File
class UploadWorker(
@@ -33,9 +35,12 @@ class UploadWorker(
if (response.status.value in 200..299) {
showUploadSuccessNotification()
Result.success()
} else Result.failure()
} else {
Log.e("UploadWorker", "Upload failed with status code: ${response.status.value}, body is ${response.body<String>()}")
Result.failure()
}
} catch (e: Exception) {
e.printStackTrace()
Log.e("UploadWorker", "Upload failed", e)
Result.failure()
}
}
+3
View File
@@ -4,6 +4,7 @@
"": {
"name": "public-photos",
"dependencies": {
"@elysiajs/static": "^1.4.4",
"elysia": "latest",
"exifreader": "^4.32.0",
"sharp": "^0.34.4",
@@ -16,6 +17,8 @@
"packages": {
"@borewit/text-codec": ["@borewit/text-codec@0.1.1", "", {}, "sha512-5L/uBxmjaCIX5h8Z+uu+kA9BQLkc/Wl06UGR5ajNRxu+/XjonB5i8JpgFMrPj3LXTCPA0pv8yxUvbUi+QthGGA=="],
"@elysiajs/static": ["@elysiajs/static@1.4.4", "", { "peerDependencies": { "elysia": ">= 1.4.0" } }, "sha512-PT/uGvBHQL5I+APAGiuRjhVfySe5YmrJdPtSc2QyM6CgNp4WDCmPfhPoVYkHNaH5QGWdP62hMq0HUnClNxR3zw=="],
"@emnapi/runtime": ["@emnapi/runtime@1.6.0", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-obtUmAHTMjll499P+D9A3axeJFlhdjOWdKUNs/U6QIGT7V5RjcUW1xToAzjvmgTSQhDbYn/NwfTRoJcQ2rNBxA=="],
"@img/colour": ["@img/colour@1.0.0", "", {}, "sha512-A5P/LfWGFSl6nsckYtjw9da+19jB8hkJ6ACTGcDfEJ0aE+l2n2El7dsVM7UVHZQ9s2lmYMWlrS21YLy2IR1LUw=="],
+1
View File
@@ -6,6 +6,7 @@
"dev": "bun run --watch src/index.ts"
},
"dependencies": {
"@elysiajs/static": "^1.4.4",
"elysia": "latest",
"exifreader": "^4.32.0",
"sharp": "^0.34.4"
+3 -21
View File
@@ -1,6 +1,7 @@
import { Elysia, redirect, t } from "elysia"
import ExifReader from "exifreader"
import { exists, mkdir } from "fs/promises"
import { staticPlugin } from "@elysiajs/static"
import sharp from "sharp"
// --- Configuration ---
@@ -105,6 +106,8 @@ export const app = new Elysia()
})
.get("/", ({ redirect }) => redirect("https://aza.moe/photo"))
.use(staticPlugin({ assets: FOLDER_PHOTOS, prefix: "/data" }))
.post("/upload", async ({ body, headers }) => {
const { owner_key, photo, edited_photo } = body
checkHeaderKey(headers)
@@ -181,27 +184,6 @@ export const app = new Elysia()
return pubMeta
})
// ----- 3. GET /photos/:id (Static File) -----
// Returns the static file for the *edited* photo.
// Respects the 'hide' flag.
.get("/photos/:id", async ({ body }) => {
const { id } = body
const metadata = await getMetadata()
const photo = metadata.find((p) => p.id === id)
// Not found or hidden
if (!photo || photo.hide === true) done(404, "Photo not found")
const file = Bun.file(photo.edited_photo)
if (!(await file.exists())) {
console.error(`Missing file for ID ${id} at ${photo.edited_photo}`)
done(404, "Photo file not found on disk")
}
return file
}, {
body: t.Object({ id: t.String() })
})
// ----- 4. POST /edit -----
// Edits a specific field in the metadata.
.post("/edit", async ({ headers, body }) => {