fix: HoverPreview not showing on collaborative editing teams
types
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import { compact } from "lodash";
|
||||
|
||||
const attachmentRegex = /\/api\/attachments\.redirect\?id=(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi;
|
||||
|
||||
export default function parseAttachmentIds(text: any): string[] {
|
||||
return [...text.matchAll(attachmentRegex)].map(
|
||||
(match) => match.groups && match.groups.id
|
||||
export default function parseAttachmentIds(text: string): string[] {
|
||||
return compact(
|
||||
[...text.matchAll(attachmentRegex)].map(
|
||||
(match) => match.groups && match.groups.id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,51 +1,52 @@
|
||||
import crypto from "crypto";
|
||||
import { addMinutes, subMinutes } from "date-fns";
|
||||
import fetch from "fetch-with-proxy";
|
||||
import { Request } from "koa";
|
||||
import { Context } from "koa";
|
||||
import { OAuthStateMismatchError } from "../errors";
|
||||
import { getCookieDomain } from "./domains";
|
||||
|
||||
export class StateStore {
|
||||
key = "state";
|
||||
|
||||
store = (req: Request, callback: () => void) => {
|
||||
store = (
|
||||
ctx: Context,
|
||||
callback: (err: Error | null, state: string) => void
|
||||
) => {
|
||||
// Produce a random string as state
|
||||
const state = crypto.randomBytes(8).toString("hex");
|
||||
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'cookies' does not exist on type 'Request... Remove this comment to see the full error message
|
||||
req.cookies.set(this.key, state, {
|
||||
ctx.cookies.set(this.key, state, {
|
||||
httpOnly: false,
|
||||
expires: addMinutes(new Date(), 10),
|
||||
domain: getCookieDomain(req.hostname),
|
||||
domain: getCookieDomain(ctx.hostname),
|
||||
});
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 2.
|
||||
|
||||
callback(null, state);
|
||||
};
|
||||
|
||||
verify = (req: Request, providedState: string, callback: () => void) => {
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'cookies' does not exist on type 'Request... Remove this comment to see the full error message
|
||||
const state = req.cookies.get(this.key);
|
||||
verify = (
|
||||
ctx: Context,
|
||||
providedState: string,
|
||||
callback: (err: Error | null, success?: boolean) => void
|
||||
) => {
|
||||
const state = ctx.cookies.get(this.key);
|
||||
|
||||
if (!state) {
|
||||
return callback(
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 1.
|
||||
new OAuthStateMismatchError("State not return in OAuth flow")
|
||||
OAuthStateMismatchError("State not return in OAuth flow")
|
||||
);
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'cookies' does not exist on type 'Request... Remove this comment to see the full error message
|
||||
req.cookies.set(this.key, "", {
|
||||
ctx.cookies.set(this.key, "", {
|
||||
httpOnly: false,
|
||||
expires: subMinutes(new Date(), 1),
|
||||
domain: getCookieDomain(req.hostname),
|
||||
domain: getCookieDomain(ctx.hostname),
|
||||
});
|
||||
|
||||
if (state !== providedState) {
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 1.
|
||||
return callback(new OAuthStateMismatchError());
|
||||
return callback(OAuthStateMismatchError());
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 2.
|
||||
callback(null, true);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import fractionalIndex from "fractional-index";
|
||||
import { Collection } from "@server/models";
|
||||
import { sequelize, Op } from "../sequelize";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param teamId The team id whose collections has to be fetched
|
||||
* @param index the index for which collision has to be checked
|
||||
* @returns An index, if there is collision returns a new index otherwise the same index
|
||||
*/
|
||||
|
||||
export default async function removeIndexCollision(
|
||||
teamId: string,
|
||||
index: string
|
||||
|
||||
@@ -7,7 +7,7 @@ import Logger from "@server/logging/logger";
|
||||
|
||||
const AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY;
|
||||
const AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID;
|
||||
const AWS_REGION = process.env.AWS_REGION;
|
||||
const AWS_REGION = process.env.AWS_REGION || "";
|
||||
const AWS_S3_UPLOAD_BUCKET_NAME = process.env.AWS_S3_UPLOAD_BUCKET_NAME || "";
|
||||
const AWS_S3_FORCE_PATH_STYLE = process.env.AWS_S3_FORCE_PATH_STYLE !== "false";
|
||||
const s3 = new AWS.S3({
|
||||
@@ -25,11 +25,13 @@ const s3 = new AWS.S3({
|
||||
signatureVersion: "v4",
|
||||
});
|
||||
|
||||
const hmac = (key: string, message: string, encoding: any) => {
|
||||
return crypto
|
||||
.createHmac("sha256", key)
|
||||
.update(message, "utf8")
|
||||
.digest(encoding);
|
||||
const hmac = (
|
||||
key: string | Buffer,
|
||||
message: string,
|
||||
encoding?: "base64" | "hex"
|
||||
) => {
|
||||
const o = crypto.createHmac("sha256", key).update(message, "utf8");
|
||||
return encoding ? o.digest(encoding) : o.digest();
|
||||
};
|
||||
|
||||
export const makeCredential = () => {
|
||||
@@ -75,20 +77,17 @@ export const makePolicy = (
|
||||
],
|
||||
expiration: format(tomorrow, "yyyy-MM-dd'T'HH:mm:ss'Z'"),
|
||||
};
|
||||
|
||||
return Buffer.from(JSON.stringify(policy)).toString("base64");
|
||||
};
|
||||
|
||||
export const getSignature = (policy: any) => {
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
|
||||
export const getSignature = (policy: string) => {
|
||||
const kDate = hmac(
|
||||
"AWS4" + AWS_SECRET_ACCESS_KEY,
|
||||
format(new Date(), "yyyyMMdd")
|
||||
);
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
|
||||
const kRegion = hmac(kDate, AWS_REGION);
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
|
||||
const kService = hmac(kRegion, "s3");
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
|
||||
const kCredentials = hmac(kService, "aws4_request");
|
||||
const signature = hmac(kCredentials, policy, "hex");
|
||||
return signature;
|
||||
@@ -198,7 +197,6 @@ export const getAWSKeyForFileOp = (teamId: string, name: string) => {
|
||||
return `${bucket}/${teamId}/${uuidv4()}/${name}-export.zip`;
|
||||
};
|
||||
|
||||
// @ts-expect-error ts-migrate(7030) FIXME: Not all code paths return a value.
|
||||
export const getFileByKey = async (key: string) => {
|
||||
const params = {
|
||||
Bucket: AWS_S3_UPLOAD_BUCKET_NAME,
|
||||
@@ -207,10 +205,12 @@ export const getFileByKey = async (key: string) => {
|
||||
|
||||
try {
|
||||
const data = await s3.getObject(params).promise();
|
||||
return data.Body;
|
||||
return data.Body || null;
|
||||
} catch (err) {
|
||||
Logger.error("Error getting file from S3 by key", err, {
|
||||
key,
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -3,11 +3,11 @@ import JSZip from "jszip";
|
||||
import tmp from "tmp";
|
||||
import Logger from "@server/logging/logger";
|
||||
import { Attachment, Collection, Document } from "@server/models";
|
||||
import { NavigationNode } from "~/types";
|
||||
import { serializeFilename } from "./fs";
|
||||
import { getFileByKey } from "./s3";
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'zip' implicitly has an 'any' type.
|
||||
async function addToArchive(zip, documents) {
|
||||
async function addToArchive(zip: JSZip, documents: NavigationNode[]) {
|
||||
for (const doc of documents) {
|
||||
const document = await Document.findByPk(doc.id);
|
||||
|
||||
@@ -39,15 +39,19 @@ async function addToArchive(zip, documents) {
|
||||
|
||||
if (doc.children && doc.children.length) {
|
||||
const folder = zip.folder(title);
|
||||
await addToArchive(folder, doc.children);
|
||||
|
||||
if (folder) {
|
||||
await addToArchive(folder, doc.children);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'zip' implicitly has an 'any' type.
|
||||
async function addImageToArchive(zip, key) {
|
||||
async function addImageToArchive(zip: JSZip, key: string) {
|
||||
try {
|
||||
const img = await getFileByKey(key);
|
||||
|
||||
// @ts-expect-error Blob
|
||||
zip.file(key, img, {
|
||||
createFolders: true,
|
||||
});
|
||||
@@ -58,8 +62,7 @@ async function addImageToArchive(zip, key) {
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'zip' implicitly has an 'any' type.
|
||||
async function archiveToPath(zip) {
|
||||
async function archiveToPath(zip: JSZip) {
|
||||
return new Promise((resolve, reject) => {
|
||||
tmp.file(
|
||||
{
|
||||
@@ -88,7 +91,10 @@ export async function archiveCollections(collections: Collection[]) {
|
||||
for (const collection of collections) {
|
||||
if (collection.documentStructure) {
|
||||
const folder = zip.folder(collection.name);
|
||||
await addToArchive(folder, collection.documentStructure);
|
||||
|
||||
if (folder) {
|
||||
await addToArchive(folder, collection.documentStructure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user