+ {!!selectedAlbumsIds.length && (
+
+ )}
setSearch(e.target.value)} />
{renderContent()}
+
)
}
diff --git a/src/pages/api/albums/share.ts b/src/pages/api/albums/share.ts
new file mode 100644
index 0000000..57b8b65
--- /dev/null
+++ b/src/pages/api/albums/share.ts
@@ -0,0 +1,61 @@
+import { ENV } from "@/config/environment";
+import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
+import { NextApiResponse } from "next";
+
+import { NextApiRequest } from "next";
+
+interface IAlbumShare {
+ albumId: string;
+ allowDownload: boolean;
+ allowUpload: boolean;
+ showMetadata: boolean;
+}
+
+const generateShareLink = async (album: IAlbumShare, token: string) => {
+ const url = ENV.IMMICH_URL + "/api/shared-links";
+ return fetch(url, {
+ method: 'POST',
+ body: JSON.stringify({
+ type: "ALBUM",
+ albumId: album.albumId,
+ allowDownload: album.allowDownload,
+ allowUpload: album.allowUpload,
+ showMetadata: album.showMetadata,
+ }),
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${token}`
+ }
+ }).then(async (response) => {
+ if (response.status >= 400) {
+ return {
+ error: "Failed to fetch assets",
+ errorData: await response.json()
+ };
+ }
+ const data = await response.json();
+ return {
+ ...album,
+ ...data,
+ shareLink: ENV.EXTERNAL_IMMICH_URL + "/share/" + data.key
+ };
+ });
+}
+
+export default async function handler(req: NextApiRequest, res: NextApiResponse) {
+ const currentUser = await getCurrentUser(req);
+
+ if (!currentUser) {
+ return res.status(401).json({ error: 'Unauthorized' });
+ }
+
+ const { albums } = req.body as { albums: IAlbumShare[] };
+ if (!albums) {
+ return res.status(400).json({ error: 'albums is required' });
+ }
+
+ const shareLinks = await Promise.all(albums.map(async (album) => {
+ return generateShareLink(album, currentUser.accessToken);
+ }));
+ return res.status(200).json(shareLinks);
+}
\ No newline at end of file