Merge main
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import subMinutes from "date-fns/sub_minutes";
|
||||
import JWT from "jsonwebtoken";
|
||||
import { AuthenticationError } from "../errors";
|
||||
import { User } from "../models";
|
||||
import { Team, User } from "../models";
|
||||
|
||||
function getJWTPayload(token) {
|
||||
let payload;
|
||||
@@ -28,7 +28,15 @@ export async function getUserForJWT(token: string): Promise<User> {
|
||||
}
|
||||
}
|
||||
|
||||
const user = await User.findByPk(payload.id);
|
||||
const user = await User.findByPk(payload.id, {
|
||||
include: [
|
||||
{
|
||||
model: Team,
|
||||
as: "team",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
if (payload.type === "transfer") {
|
||||
// If the user has made a single API request since the transfer token was
|
||||
|
||||
@@ -2,48 +2,63 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import * as React from "react";
|
||||
import webpackConfig from "../../webpack.config";
|
||||
import ReactDOMServer from "react-dom/server";
|
||||
import env from "../env";
|
||||
|
||||
const PUBLIC_PATH = webpackConfig.output.publicPath;
|
||||
const prefetchTags = [];
|
||||
|
||||
const prefetchTags = [
|
||||
<link
|
||||
rel="dns-prefetch"
|
||||
href={process.env.AWS_S3_UPLOAD_BUCKET_URL}
|
||||
key="dns"
|
||||
/>,
|
||||
];
|
||||
if (process.env.AWS_S3_UPLOAD_BUCKET_URL) {
|
||||
prefetchTags.push(
|
||||
<link
|
||||
rel="dns-prefetch"
|
||||
href={process.env.AWS_S3_UPLOAD_BUCKET_URL}
|
||||
key="dns"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
let manifestData = {};
|
||||
try {
|
||||
const manifest = fs.readFileSync(
|
||||
path.join(__dirname, "../../app/manifest.json"),
|
||||
"utf8"
|
||||
);
|
||||
const manifestData = JSON.parse(manifest);
|
||||
Object.values(manifestData).forEach((filename) => {
|
||||
if (typeof filename !== "string") return;
|
||||
if (filename.endsWith(".js")) {
|
||||
manifestData = JSON.parse(manifest);
|
||||
} catch (err) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
let index = 0;
|
||||
Object.values(manifestData).forEach((filename) => {
|
||||
if (typeof filename !== "string") return;
|
||||
if (!env.CDN_URL) return;
|
||||
|
||||
if (filename.endsWith(".js")) {
|
||||
// Preload resources you have high-confidence will be used in the current
|
||||
// page.Prefetch resources likely to be used for future navigations
|
||||
const shouldPreload =
|
||||
filename.includes("/main") ||
|
||||
filename.includes("/runtime") ||
|
||||
filename.includes("/vendors");
|
||||
|
||||
// only prefetch the first few javascript chunks or it gets out of hand fast
|
||||
const shouldPrefetch = ++index <= 6;
|
||||
|
||||
if (shouldPreload || shouldPrefetch) {
|
||||
prefetchTags.push(
|
||||
<link
|
||||
rel="prefetch"
|
||||
href={`${PUBLIC_PATH}${filename}`}
|
||||
rel={shouldPreload ? "preload" : "prefetch"}
|
||||
href={filename}
|
||||
key={filename}
|
||||
as="script"
|
||||
/>
|
||||
);
|
||||
} else if (filename.endsWith(".css")) {
|
||||
prefetchTags.push(
|
||||
<link
|
||||
rel="prefetch"
|
||||
href={`${PUBLIC_PATH}${filename}`}
|
||||
key={filename}
|
||||
as="style"
|
||||
/>
|
||||
);
|
||||
}
|
||||
});
|
||||
} catch (_e) {
|
||||
// no-op
|
||||
}
|
||||
} else if (filename.endsWith(".css")) {
|
||||
prefetchTags.push(
|
||||
<link rel="prefetch" href={filename} key={filename} as="style" />
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export default prefetchTags;
|
||||
export default ReactDOMServer.renderToString(prefetchTags);
|
||||
|
||||
@@ -16,7 +16,7 @@ const s3 = new AWS.S3({
|
||||
s3ForcePathStyle: AWS_S3_FORCE_PATH_STYLE,
|
||||
accessKeyId: AWS_ACCESS_KEY_ID,
|
||||
secretAccessKey: AWS_SECRET_ACCESS_KEY,
|
||||
endpoint: new AWS.Endpoint(process.env.AWS_S3_UPLOAD_BUCKET_URL),
|
||||
region: AWS_REGION,
|
||||
signatureVersion: "v4",
|
||||
});
|
||||
|
||||
@@ -84,6 +84,14 @@ export const publicS3Endpoint = (isServerUpload?: boolean) => {
|
||||
"localhost:"
|
||||
).replace(/\/$/, "");
|
||||
|
||||
// support old path-style S3 uploads and new virtual host uploads by checking
|
||||
// for the bucket name in the endpoint url before appending.
|
||||
const isVirtualHost = host.includes(AWS_S3_UPLOAD_BUCKET_NAME);
|
||||
|
||||
if (isVirtualHost) {
|
||||
return host;
|
||||
}
|
||||
|
||||
return `${host}/${
|
||||
isServerUpload && isDocker ? "s3/" : ""
|
||||
}${AWS_S3_UPLOAD_BUCKET_NAME}`;
|
||||
|
||||
Reference in New Issue
Block a user