fix(api): update view counting endpoint

ensure that an `undefined` ip doesn't get added to the cache store
This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2024-11-11 18:42:29 -05:00
parent 686acb595b
commit a96f924f1e
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

View File

@ -3,7 +3,7 @@ import { Story } from "@models/stories";
export default eventHandler(async (ev) => {
const id = isIdNan(ev);
const ip = await getRequestIP(ev, { xForwardedFor: true });
const ip = getRequestIP(ev, { xForwardedFor: true });
const storage = useStorage(`/story/${id}/viewMap`);
if (ev.context.currentUser) {
if (!(await storage.hasItem(`loggedIn/${ev.context.currentUser._id}`))) {
@ -14,7 +14,7 @@ export default eventHandler(async (ev) => {
});
}
await storage.setItem(`loggedIn/${ev.context.currentUser._id}`, Date.now());
} else {
} else if (!!ip) {
if (!(await storage.hasItem(`/loggedIn/${ip}`))) {
await Story.findByIdAndUpdate(id, {
$inc: {