mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -113,16 +113,31 @@ exports.issueTokensBatch = async (req, res) => {
|
||||
storage_provider: "s3",
|
||||
deletedAt: null,
|
||||
},
|
||||
attributes: ["asset_id", "file_type", "storage_key", "mime_type"],
|
||||
attributes: ["asset_id", "file_type", "storage_key", "mime_type", "thumbnail_storage_key"],
|
||||
});
|
||||
|
||||
const ip = resolveIp(req);
|
||||
const tokens = {};
|
||||
const ip = resolveIp(req);
|
||||
const tokens = {};
|
||||
const thumbnails = {};
|
||||
|
||||
for (const asset of assets) {
|
||||
tokens[String(asset.asset_id)] = signToken(asset, req.user.user_id, ip);
|
||||
|
||||
// For image/video assets with a thumbnail — presign it so the browser can
|
||||
// load it directly from Garage without going through the stream proxy.
|
||||
if (asset.thumbnail_storage_key) {
|
||||
try {
|
||||
thumbnails[String(asset.asset_id)] = await s3.getSignedDownloadUrl(
|
||||
asset.thumbnail_storage_key,
|
||||
TOKEN_TTL_SEC,
|
||||
);
|
||||
} catch {
|
||||
// Non-fatal — stream token is the fallback
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return R.success(res, "Tokens issued.", { tokens });
|
||||
return R.success(res, "Tokens issued.", { tokens, thumbnails });
|
||||
} catch (err) {
|
||||
console.error("[ADMIN][MEDIA][TOKENS BATCH]", err);
|
||||
return R.error(res, "Could not issue media tokens.", 500);
|
||||
|
||||
Reference in New Issue
Block a user