Ability to create share url slug (#4550)

* feat: share url slug

* feat: add col urlId

* feat: allow updating urlId

* fix: typo

* fix: migrations

* fix: urlId model validation

* fix: input label

* fix: debounce slug request

* feat: link preview

* fix: send slug variant in response if available

* fix: temporary redirect to slug variant if available

* fix: move up the custom link field

* fix: process and display backend err

* fix: reset custom link state on popover close and remove isCopied

* fix: document link preview

* fix: set urlId when available

* fix: keep unique(urlId, teamId)

* fix: codeql

* fix: get rid of preview type

* fix: width not needed for block elem

* fix: migrations

* fix: array not required

* fix: use val

* fix: validation on shareId and test

* fix: allow clearing urlId

* fix: do not escape

* fix: unique error text

* fix: keep team
This commit is contained in:
Apoorv Mishra
2022-12-14 06:56:36 +05:30
committed by GitHub
parent b9dd060736
commit 79829a3129
16 changed files with 288 additions and 14 deletions

View File

@@ -4,9 +4,11 @@ import util from "util";
import { Context, Next } from "koa";
import { escape } from "lodash";
import { Sequelize } from "sequelize";
import isUUID from "validator/lib/isUUID";
import documentLoader from "@server/commands/documentLoader";
import env from "@server/env";
import presentEnv from "@server/presenters/env";
import { getTeamFromContext } from "@server/utils/passport";
import prefetchTags from "@server/utils/prefetchTags";
const isProduction = env.ENVIRONMENT === "production";
@@ -87,11 +89,19 @@ export const renderShare = async (ctx: Context, next: Next) => {
let share, document;
try {
const team = await getTeamFromContext(ctx);
const result = await documentLoader({
id: documentSlug,
shareId,
teamId: team?.id,
});
share = result.share;
if (isUUID(shareId) && share && share.urlId) {
// Redirect temporarily because the url slug
// can be modified by the user at any time
ctx.redirect(`/s/${share.urlId}`);
ctx.status = 307;
}
document = result.document;
if (share && !ctx.userAgent.isBot) {