Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/gregordr/ImageStore into test
Browse files Browse the repository at this point in the history
  • Loading branch information
gregordr committed May 26, 2024
2 parents 35458b6 + 536bf42 commit 813f445
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ frontend/.eslintcache

# macOS
.DS_Store

faceFeatures/*
imageFeatures/*
autoImport/node_modules/*
Expand Down
144 changes: 70 additions & 74 deletions backend/src/routers/albumRouter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import axios from 'axios';
import express from 'express';
import { getAlbums, addAlbum, addPhotosToAlbums, removePhotosFromAlbum, deleteAlbum, getMediaInAlbum, setCover, rename, getAlbumsWithMedia, addFolder, putAlbumIntoFolder, putFolderIntoFolder, deleteFolder, getFolders, getFolderAlbumRelation, getFolderFolderRelation, renameFolder } from '../database/albumDatabase';
import { registeredServices } from './servicesRouter';
import axios from "axios";
import express from "express";
import { getAlbums, addAlbum, addPhotosToAlbums, removePhotosFromAlbum, deleteAlbum, getMediaInAlbum, setCover, rename, getAlbumsWithMedia, addFolder, putAlbumIntoFolder, putFolderIntoFolder, deleteFolder, getFolders, getFolderAlbumRelation, getFolderFolderRelation, renameFolder } from "../database/albumDatabase";
import { registeredServices } from "./servicesRouter";

export const router = express.Router();

router.post('/newFolder', async (req, res) => {
router.post("/newFolder", async (req, res) => {
try {
res.status(200).send(await addFolder(req.body.folderName, req.body.parentId));
} catch (err) {
res.status(500).send(err.toString());
}
});

router.post('/new/:name', async (req, res) => {
router.post("/new/:name", async (req, res) => {
const name = req.params.name;
try {
res.status(200).send(await addAlbum(name, req.body.parentId));
Expand All @@ -22,23 +22,23 @@ router.post('/new/:name', async (req, res) => {
}
});

router.post('/deleteFolder/:name', async (req, res) => {
router.post("/deleteFolder/:name", async (req, res) => {
const name = req.params.name;
try {
res.status(200).send(await deleteFolder(name));
} catch (err) {
res.status(500).send(err.toString());
}
});
router.post('/renameFolder', async (req, res) => {
router.post("/renameFolder", async (req, res) => {
try {
res.status(200).send(await renameFolder(req.body.oid, req.body.newName));
} catch (err) {
res.status(500).send(err.toString());
}
});

router.post('/delete/:name', async (req, res) => {
router.post("/delete/:name", async (req, res) => {
const name = req.params.name;
try {
res.status(200).send(await deleteAlbum(name));
Expand All @@ -47,47 +47,47 @@ router.post('/delete/:name', async (req, res) => {
}
});

router.get('/folders', async (req, res) => {
router.get("/folders", async (req, res) => {
try {
res.status(200).send(await getFolders());
} catch (err) {
res.status(500).send(err.toString());
}
});

router.get('/getFolderFolderRelation', async (req, res) => {
router.get("/getFolderFolderRelation", async (req, res) => {
try {
res.status(200).send(await getFolderFolderRelation())
res.status(200).send(await getFolderFolderRelation());
} catch (err) {
res.status(500).send(err.toString())
res.status(500).send(err.toString());
}
});

router.get('/getFolderAlbumRelation', async (req, res) => {
router.get("/getFolderAlbumRelation", async (req, res) => {
try {
res.status(200).send(await getFolderAlbumRelation())
res.status(200).send(await getFolderAlbumRelation());
} catch (err) {
res.status(500).send(err.toString())
res.status(500).send(err.toString());
}
});

router.post('/putFolderIntoFolder', async (req, res) => {
router.post("/putFolderIntoFolder", async (req, res) => {
try {
res.status(200).send(await putFolderIntoFolder(req.body.childId, req.body.parentId))
res.status(200).send(await putFolderIntoFolder(req.body.childId, req.body.parentId));
} catch (err) {
res.status(500).send(err.toString())
res.status(500).send(err.toString());
}
});

router.post('/putAlbumIntoFolder', async (req, res) => {
router.post("/putAlbumIntoFolder", async (req, res) => {
try {
res.status(200).send(await putAlbumIntoFolder(req.body.childId, req.body.parentId))
res.status(200).send(await putAlbumIntoFolder(req.body.childId, req.body.parentId));
} catch (err) {
res.status(500).send(err.toString())
res.status(500).send(err.toString());
}
});

router.get('/all', async (req, res) => {
router.get("/all", async (req, res) => {
try {
res.status(200).send(await getAlbums("%"));
} catch (err) {
Expand All @@ -103,39 +103,38 @@ router.get("/getAlbumsWithMedia/:photoID", async (req, res) => {
}
});

router.get('/:name/all', async (req, res) => {
router.get("/:name/all", async (req, res) => {
try {
res.status(200).send(await getMediaInAlbum(req.params.name, "%", ""));
} catch (err) {
res.status(500).send(err.toString());
}
});

router.get('/:name/search/:term', async (req, res) => {
router.get("/:name/search/:term", async (req, res) => {
try {
if (registeredServices && registeredServices["search"]) {
const searchResult = await getMediaInAlbum(req.params.name, "%", "")
const searchResult = await getMediaInAlbum(req.params.name, "%", "");

const data = await axios.post("http://" + registeredServices["search"].values().next().value + "/searchByText",
{
text: req.params.term,
candidates: searchResult.map((photo: any) => photo.id)
})
const data = await axios.post("http://" + registeredServices["search"].values().next().value + "/searchByText", {
text: req.params.term,
candidates: searchResult.map((photo: any) => photo.id),
});

const map: any = {}
const map: any = {};

searchResult.forEach((photo: any) => {
map[photo.id] = photo
})
map[photo.id] = photo;
});

const response = []
const response = [];

for (const id of (data.data as any)) {
response.push(map[id])
for (const id of data.data as any) {
response.push(map[id]);
}

res.status(200).send(response);
return
return;
}

res.status(200).send(await getMediaInAlbum(req.params.name, `%${req.params.term}%`, req.params.term));
Expand All @@ -144,7 +143,7 @@ router.get('/:name/search/:term', async (req, res) => {
}
});

router.get('/:name/searchByTag/:term', async (req, res) => {
router.get("/:name/searchByTag/:term", async (req, res) => {
try {
res.status(200).send(await getMediaInAlbum(req.params.name, ``, req.params.term));
} catch (err) {
Expand All @@ -155,29 +154,28 @@ router.get('/:name/searchByTag/:term', async (req, res) => {
router.get("/:name/searchByImage/:imageId", async (req, res) => {
try {
if (registeredServices && registeredServices["search"]) {
const searchResult = await getMediaInAlbum(req.params.name, "%", "")
const searchResult = await getMediaInAlbum(req.params.name, "%", "");

const data = await axios.post("http://" + registeredServices["search"].values().next().value + "/searchByImage",
{
image: req.params.imageId,
type: (searchResult.find((photo: any) => photo.id === req.params.imageId) as any).type,
candidates: searchResult.map((photo: any) => photo.id)
})
const data = await axios.post("http://" + registeredServices["search"].values().next().value + "/searchByImage", {
image: req.params.imageId,
type: (searchResult.find((photo: any) => photo.id === req.params.imageId) as any).type,
candidates: searchResult.map((photo: any) => photo.id),
});

const map: any = {}
const map: any = {};

searchResult.forEach((photo: any) => {
map[photo.id] = photo
})
map[photo.id] = photo;
});

const response = []
const response = [];

for (const id of (data.data as any)) {
response.push(map[id])
for (const id of data.data as any) {
response.push(map[id]);
}

res.status(200).send(response);
return
return;
}
res.status(200).send(await getMediaInAlbum(req.params.name, `%${req.params.term}%`, req.params.term));
} catch (err) {
Expand All @@ -188,80 +186,78 @@ router.get("/:name/searchByImage/:imageId", async (req, res) => {
router.get("/:name/searchByFace/:imageId", async (req, res) => {
try {
if (registeredServices && registeredServices["face"]) {
const searchResult = await getMediaInAlbum(req.params.name, "%", "")
const searchResult = await getMediaInAlbum(req.params.name, "%", "");

const data = await axios.post("http://" + registeredServices["face"].values().next().value + "/searchByFace",
{
image: req.params.imageId,
candidates: searchResult.map((photo: any) => photo.id)
})
const data = await axios.post("http://" + registeredServices["face"].values().next().value + "/searchByFace", {
image: req.params.imageId,
candidates: searchResult.map((photo: any) => photo.id),
});

const map: any = {}
const map: any = {};

searchResult.forEach((photo: any) => {
map[photo.id] = photo
})
map[photo.id] = photo;
});

const response = []
const response = [];

for (const id of (data.data as any)) {
response.push(map[id])
for (const id of data.data as any) {
response.push(map[id]);
}

res.status(200).send(response);
return
return;
}
res.status(200).send(await getMediaInAlbum(req.params.name, `%${req.params.term}%`, req.params.term));
} catch (err) {
res.status(500).send(err.toString());
}
});

router.get('/search/:term', async (req, res) => {
router.get("/search/:term", async (req, res) => {
try {
res.status(200).send(await getAlbums(`%${req.params.term}%`));
} catch (err) {
res.status(500).send(err.toString());
}
});

router.post('/addPhotos/', async (req, res) => {
router.post("/addPhotos/", async (req, res) => {
try {
res.status(200).send(await (await addPhotosToAlbums(req.body.photos, req.body.albums)).toString());
} catch (err) {
res.status(500).send(err.toString());
}
});

router.post('/remove', async (req, res) => {
router.post("/remove", async (req, res) => {
try {
res.status(200).send(await removePhotosFromAlbum(req.body.albumId, req.body.photoIds));
} catch (err) {
res.status(500).send(err.toString());
}
});

router.post('/setCover/:albumID/:photoID', async (req, res) => {
router.post("/setCover/:albumID/:photoID", async (req, res) => {
try {
res.status(200).send(await setCover(req.params.albumID, req.params.photoID));
} catch (err) {
res.status(500).send(err.toString());
}
});


router.post('/clearCover/:albumID', async (req, res) => {
router.post("/clearCover/:albumID", async (req, res) => {
try {
res.status(200).send(await setCover(req.params.albumID, null));
} catch (err) {
res.status(500).send(err.toString());
}
});

router.post('/rename', async (req, res) => {
router.post("/rename", async (req, res) => {
try {
res.status(200).send(await rename(req.body.albumId, req.body.newAlbumName));
} catch (err) {
res.status(500).send(err.toString());
}
});
});
1 change: 0 additions & 1 deletion frontend/src/Components/Shared/PhotoGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ function Photo(props: any) {
height: props.y,
width: props.x - leftMargin,
marginLeft: leftMargin,
// boxShadow: props.marked ? `inset 0px 0px 0px 100px rgb(0,0,255,0.6)` : ""
}}
onMouseEnter={async () => {
setVis(0.4);
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/Components/Shared/PhotoPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default function PhotoPage(props: { handleDrawerToggle: () => void; drawe
};

useEffect(() => {
history.push(rawSearchQuery === "" ? {} : { search: qs.stringify({ search: rawSearchQuery }) })
setPhotos([])
fetchPhotos();
fetchAlbums();
Expand Down Expand Up @@ -496,7 +497,7 @@ export default function PhotoPage(props: { handleDrawerToggle: () => void; drawe
searchByTag={(tag: string) => { searchByTag(tag) }}
searchByFace={searchByFace}
searchByImageEnabled={props.searchByImageEnabled} ></ViewPage>
</Route>
</Route >
<Route path="/">
<div {...getRootProps({ className: "dropzone" })} className={classes.root}>
<Backdrop
Expand Down Expand Up @@ -572,10 +573,10 @@ export default function PhotoPage(props: { handleDrawerToggle: () => void; drawe
</main>
</div>
</Route>
</Switch>
</Switch >
<AddToAlbum albums={albums} open={albumDialogOpen} setOpen={setAlbumDialogOpen} cb={albumDialogCallback} />
<AddLabels open={labelDialogOpen} setOpen={setLabelDialogOpen} cb={labelDialogCallback}></AddLabels>
<ConfirmDeleteDialog state={onDeleteDialogState}></ConfirmDeleteDialog>
</div>
</div >
);
}
6 changes: 3 additions & 3 deletions frontend/src/Components/ViewPage/ViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ export default function ViewPage(props: { photos: PhotoT[]; setViewId: (arg0: st
<TopLeftBar />
{props.topRightBar(id, modifiedButtonFunctions, props.searchByImageEnabled)}
</div>
</ThemeProvider>
</main>
</ThemeProvider >
</main >
<Drawer
className={classes.drawer}
variant="persistent"
Expand Down Expand Up @@ -508,7 +508,7 @@ export default function ViewPage(props: { photos: PhotoT[]; setViewId: (arg0: st
</Tooltip>
</ListItem>

</List>
</List >
</Drawer >
<EditPropsDialog open={editPropsOpen} setOpen={setEditPropsOpen} cb={editPropsCb} photo={props.photos[index]} />
<EditLocationDialog open={editLocationOpen} setOpen={setEditLocationOpen} cb={editLocationCb} photo={props.photos[index]} />
Expand Down

0 comments on commit 813f445

Please sign in to comment.