fix(api): update view counting endpoint
ensure that an `undefined` ip doesn't get added to the cache store
This commit is contained in:
parent
686acb595b
commit
a96f924f1e
@ -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: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user