Add simple count of views to share links (#4036)
* Add simple count of views to share links * Remove no longer applicable tests * Avoid incrementing view count for known bots
This commit is contained in:
@@ -3,6 +3,7 @@ import path from "path";
|
||||
import util from "util";
|
||||
import { Context, Next } from "koa";
|
||||
import { escape } from "lodash";
|
||||
import { Sequelize } from "sequelize";
|
||||
import documentLoader from "@server/commands/documentLoader";
|
||||
import env from "@server/env";
|
||||
import presentEnv from "@server/presenters/env";
|
||||
@@ -81,6 +82,13 @@ export const renderShare = async (ctx: Context, next: Next) => {
|
||||
});
|
||||
share = result.share;
|
||||
document = result.document;
|
||||
|
||||
if (share && !ctx.userAgent.isBot) {
|
||||
await share.update({
|
||||
lastAccessedAt: new Date(),
|
||||
views: Sequelize.literal("views + 1"),
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
// If the share or document does not exist, return a 404.
|
||||
ctx.status = 404;
|
||||
|
||||
Reference in New Issue
Block a user