chore: Move to prettier standard double quotes (#1309)
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
// @flow
|
||||
import JWT from 'jsonwebtoken';
|
||||
import subMinutes from 'date-fns/sub_minutes';
|
||||
import { AuthenticationError } from '../errors';
|
||||
import { User } from '../models';
|
||||
import JWT from "jsonwebtoken";
|
||||
import subMinutes from "date-fns/sub_minutes";
|
||||
import { AuthenticationError } from "../errors";
|
||||
import { User } from "../models";
|
||||
|
||||
function getJWTPayload(token) {
|
||||
let payload;
|
||||
try {
|
||||
payload = JWT.decode(token);
|
||||
} catch (err) {
|
||||
throw new AuthenticationError('Unable to decode JWT token');
|
||||
throw new AuthenticationError("Unable to decode JWT token");
|
||||
}
|
||||
|
||||
if (!payload) {
|
||||
throw new AuthenticationError('Invalid token');
|
||||
throw new AuthenticationError("Invalid token");
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ export async function getUserForJWT(token: string) {
|
||||
try {
|
||||
JWT.verify(token, user.jwtSecret);
|
||||
} catch (err) {
|
||||
throw new AuthenticationError('Invalid token');
|
||||
throw new AuthenticationError("Invalid token");
|
||||
}
|
||||
|
||||
return user;
|
||||
@@ -37,7 +37,7 @@ export async function getUserForEmailSigninToken(token: string) {
|
||||
// check the token is within it's expiration time
|
||||
if (payload.createdAt) {
|
||||
if (new Date(payload.createdAt) < subMinutes(new Date(), 10)) {
|
||||
throw new AuthenticationError('Expired token');
|
||||
throw new AuthenticationError("Expired token");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ export async function getUserForEmailSigninToken(token: string) {
|
||||
// if user has signed in at all since the token was created then
|
||||
// it's no longer valid, they'll need a new one.
|
||||
if (user.lastSignedInAt > payload.createdAt) {
|
||||
throw new AuthenticationError('Token has already been used');
|
||||
throw new AuthenticationError("Token has already been used");
|
||||
}
|
||||
|
||||
try {
|
||||
JWT.verify(token, user.jwtSecret);
|
||||
} catch (err) {
|
||||
throw new AuthenticationError('Invalid token');
|
||||
throw new AuthenticationError("Invalid token");
|
||||
}
|
||||
|
||||
return user;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import webpackConfig from '../../webpack.config';
|
||||
import * as React from "react";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import webpackConfig from "../../webpack.config";
|
||||
|
||||
const PUBLIC_PATH = webpackConfig.output.publicPath;
|
||||
|
||||
@@ -16,13 +16,13 @@ const prefetchTags = [
|
||||
|
||||
try {
|
||||
const manifest = fs.readFileSync(
|
||||
path.join(__dirname, '../../dist/manifest.json'),
|
||||
'utf8'
|
||||
path.join(__dirname, "../../dist/manifest.json"),
|
||||
"utf8"
|
||||
);
|
||||
const manifestData = JSON.parse(manifest);
|
||||
Object.values(manifestData).forEach(filename => {
|
||||
if (typeof filename !== 'string') return;
|
||||
if (filename.endsWith('.js')) {
|
||||
if (typeof filename !== "string") return;
|
||||
if (filename.endsWith(".js")) {
|
||||
prefetchTags.push(
|
||||
<link
|
||||
rel="prefetch"
|
||||
@@ -31,7 +31,7 @@ try {
|
||||
as="script"
|
||||
/>
|
||||
);
|
||||
} else if (filename.endsWith('.css')) {
|
||||
} else if (filename.endsWith(".css")) {
|
||||
prefetchTags.push(
|
||||
<link
|
||||
rel="prefetch"
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
// @flow
|
||||
import Redis from 'ioredis';
|
||||
import Queue from 'bull';
|
||||
import { client, subscriber } from '../redis';
|
||||
import Redis from "ioredis";
|
||||
import Queue from "bull";
|
||||
import { client, subscriber } from "../redis";
|
||||
|
||||
export function createQueue(name: string) {
|
||||
return new Queue(name, {
|
||||
createClient(type) {
|
||||
switch (type) {
|
||||
case 'client':
|
||||
case "client":
|
||||
return client;
|
||||
case 'subscriber':
|
||||
case "subscriber":
|
||||
return subscriber;
|
||||
default:
|
||||
return new Redis(process.env.REDIS_URL);
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import ReactDOMServer from 'react-dom/server';
|
||||
import { Helmet } from 'react-helmet';
|
||||
import * as React from "react";
|
||||
import ReactDOMServer from "react-dom/server";
|
||||
import { Helmet } from "react-helmet";
|
||||
import {
|
||||
ServerStyleSheet,
|
||||
StyleSheetManager,
|
||||
ThemeProvider,
|
||||
} from 'styled-components';
|
||||
import Layout from '../pages/components/Layout';
|
||||
import { light } from '../../shared/styles/theme';
|
||||
} from "styled-components";
|
||||
import Layout from "../pages/components/Layout";
|
||||
import { light } from "../../shared/styles/theme";
|
||||
|
||||
export default function renderpage(ctx: Object, children: React.Node) {
|
||||
let sessions = {};
|
||||
try {
|
||||
sessions = JSON.parse(
|
||||
decodeURIComponent(ctx.cookies.get('sessions') || '') || '{}'
|
||||
decodeURIComponent(ctx.cookies.get("sessions") || "") || "{}"
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(`Sessions cookie could not be parsed: ${err}`);
|
||||
@@ -22,7 +22,7 @@ export default function renderpage(ctx: Object, children: React.Node) {
|
||||
|
||||
const sheet = new ServerStyleSheet();
|
||||
const loggedIn = !!(
|
||||
ctx.cookies.get('accessToken') || Object.keys(sessions).length
|
||||
ctx.cookies.get("accessToken") || Object.keys(sessions).length
|
||||
);
|
||||
|
||||
const html = ReactDOMServer.renderToString(
|
||||
@@ -37,11 +37,11 @@ export default function renderpage(ctx: Object, children: React.Node) {
|
||||
|
||||
// helmet returns an object of meta tags with toString methods, urgh.
|
||||
const helmet = Helmet.renderStatic();
|
||||
let head = '';
|
||||
let head = "";
|
||||
// $FlowFixMe
|
||||
Object.keys(helmet).forEach(key => (head += helmet[key].toString()));
|
||||
|
||||
ctx.body = `<!DOCTYPE html>\n${html}`
|
||||
.replace('{{CSS}}', sheet.getStyleTags())
|
||||
.replace('{{HEAD}}', head);
|
||||
.replace("{{CSS}}", sheet.getStyleTags())
|
||||
.replace("{{HEAD}}", head);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// @flow
|
||||
import { type Context } from 'koa';
|
||||
import { type Context } from "koa";
|
||||
|
||||
const DISALLOW_ROBOTS = `User-agent: *
|
||||
Disallow: /`;
|
||||
|
||||
export const robotsResponse = (ctx: Context): ?string => {
|
||||
if (ctx.headers.host.indexOf('getoutline.com') < 0) return DISALLOW_ROBOTS;
|
||||
if (ctx.headers.host.indexOf("getoutline.com") < 0) return DISALLOW_ROBOTS;
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// @flow
|
||||
import crypto from 'crypto';
|
||||
import addHours from 'date-fns/add_hours';
|
||||
import format from 'date-fns/format';
|
||||
import AWS from 'aws-sdk';
|
||||
import invariant from 'invariant';
|
||||
import fetch from 'isomorphic-fetch';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import crypto from "crypto";
|
||||
import addHours from "date-fns/add_hours";
|
||||
import format from "date-fns/format";
|
||||
import AWS from "aws-sdk";
|
||||
import invariant from "invariant";
|
||||
import fetch from "isomorphic-fetch";
|
||||
import * as Sentry from "@sentry/node";
|
||||
|
||||
const AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY;
|
||||
const AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID;
|
||||
@@ -17,24 +17,24 @@ const s3 = new AWS.S3({
|
||||
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
||||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
||||
endpoint: new AWS.Endpoint(process.env.AWS_S3_UPLOAD_BUCKET_URL),
|
||||
signatureVersion: 'v4',
|
||||
signatureVersion: "v4",
|
||||
});
|
||||
|
||||
const hmac = (key: string, message: string, encoding: any) => {
|
||||
return crypto
|
||||
.createHmac('sha256', key)
|
||||
.update(message, 'utf8')
|
||||
.createHmac("sha256", key)
|
||||
.update(message, "utf8")
|
||||
.digest(encoding);
|
||||
};
|
||||
|
||||
export const makeCredential = () => {
|
||||
const credential =
|
||||
AWS_ACCESS_KEY_ID +
|
||||
'/' +
|
||||
format(new Date(), 'YYYYMMDD') +
|
||||
'/' +
|
||||
"/" +
|
||||
format(new Date(), "YYYYMMDD") +
|
||||
"/" +
|
||||
AWS_REGION +
|
||||
'/s3/aws4_request';
|
||||
"/s3/aws4_request";
|
||||
return credential;
|
||||
};
|
||||
|
||||
@@ -47,31 +47,31 @@ export const makePolicy = (
|
||||
const policy = {
|
||||
conditions: [
|
||||
{ bucket: process.env.AWS_S3_UPLOAD_BUCKET_NAME },
|
||||
['starts-with', '$key', ''],
|
||||
["starts-with", "$key", ""],
|
||||
{ acl },
|
||||
['content-length-range', 0, +process.env.AWS_S3_UPLOAD_MAX_SIZE],
|
||||
['starts-with', '$Content-Type', 'image'],
|
||||
['starts-with', '$Cache-Control', ''],
|
||||
{ 'x-amz-algorithm': 'AWS4-HMAC-SHA256' },
|
||||
{ 'x-amz-credential': credential },
|
||||
{ 'x-amz-date': longDate },
|
||||
["content-length-range", 0, +process.env.AWS_S3_UPLOAD_MAX_SIZE],
|
||||
["starts-with", "$Content-Type", "image"],
|
||||
["starts-with", "$Cache-Control", ""],
|
||||
{ "x-amz-algorithm": "AWS4-HMAC-SHA256" },
|
||||
{ "x-amz-credential": credential },
|
||||
{ "x-amz-date": longDate },
|
||||
],
|
||||
expiration: format(tomorrow, 'YYYY-MM-DDTHH:mm:ss\\Z'),
|
||||
expiration: format(tomorrow, "YYYY-MM-DDTHH:mm:ss\\Z"),
|
||||
};
|
||||
|
||||
return new Buffer(JSON.stringify(policy)).toString('base64');
|
||||
return new Buffer(JSON.stringify(policy)).toString("base64");
|
||||
};
|
||||
|
||||
export const getSignature = (policy: any) => {
|
||||
const kDate = hmac(
|
||||
'AWS4' + AWS_SECRET_ACCESS_KEY,
|
||||
format(new Date(), 'YYYYMMDD')
|
||||
"AWS4" + AWS_SECRET_ACCESS_KEY,
|
||||
format(new Date(), "YYYYMMDD")
|
||||
);
|
||||
const kRegion = hmac(kDate, AWS_REGION);
|
||||
const kService = hmac(kRegion, 's3');
|
||||
const kCredentials = hmac(kService, 'aws4_request');
|
||||
const kService = hmac(kRegion, "s3");
|
||||
const kCredentials = hmac(kService, "aws4_request");
|
||||
|
||||
const signature = hmac(kCredentials, policy, 'hex');
|
||||
const signature = hmac(kCredentials, policy, "hex");
|
||||
return signature;
|
||||
};
|
||||
|
||||
@@ -80,11 +80,11 @@ export const publicS3Endpoint = (isServerUpload?: boolean) => {
|
||||
// for access outside of docker containers in local development
|
||||
const isDocker = process.env.AWS_S3_UPLOAD_BUCKET_URL.match(/http:\/\/s3:/);
|
||||
const host = process.env.AWS_S3_UPLOAD_BUCKET_URL.replace(
|
||||
's3:',
|
||||
'localhost:'
|
||||
).replace(/\/$/, '');
|
||||
"s3:",
|
||||
"localhost:"
|
||||
).replace(/\/$/, "");
|
||||
|
||||
return `${host}/${isServerUpload && isDocker ? 's3/' : ''}${
|
||||
return `${host}/${isServerUpload && isDocker ? "s3/" : ""}${
|
||||
process.env.AWS_S3_UPLOAD_BUCKET_NAME
|
||||
}`;
|
||||
};
|
||||
@@ -94,7 +94,7 @@ export const uploadToS3FromUrl = async (
|
||||
key: string,
|
||||
acl: string
|
||||
) => {
|
||||
invariant(AWS_S3_UPLOAD_BUCKET_NAME, 'AWS_S3_UPLOAD_BUCKET_NAME not set');
|
||||
invariant(AWS_S3_UPLOAD_BUCKET_NAME, "AWS_S3_UPLOAD_BUCKET_NAME not set");
|
||||
|
||||
try {
|
||||
// $FlowIssue https://github.com/facebook/flow/issues/2171
|
||||
@@ -105,9 +105,9 @@ export const uploadToS3FromUrl = async (
|
||||
ACL: acl,
|
||||
Bucket: process.env.AWS_S3_UPLOAD_BUCKET_NAME,
|
||||
Key: key,
|
||||
ContentType: res.headers['content-type'],
|
||||
ContentLength: res.headers['content-length'],
|
||||
ServerSideEncryption: 'AES256',
|
||||
ContentType: res.headers["content-type"],
|
||||
ContentLength: res.headers["content-length"],
|
||||
ServerSideEncryption: "AES256",
|
||||
Body: buffer,
|
||||
})
|
||||
.promise();
|
||||
@@ -133,7 +133,7 @@ export const deleteFromS3 = (key: string) => {
|
||||
};
|
||||
|
||||
export const getSignedImageUrl = async (key: string) => {
|
||||
invariant(AWS_S3_UPLOAD_BUCKET_NAME, 'AWS_S3_UPLOAD_BUCKET_NAME not set');
|
||||
invariant(AWS_S3_UPLOAD_BUCKET_NAME, "AWS_S3_UPLOAD_BUCKET_NAME not set");
|
||||
const isDocker = process.env.AWS_S3_UPLOAD_BUCKET_URL.match(/http:\/\/s3:/);
|
||||
|
||||
const params = {
|
||||
@@ -144,7 +144,7 @@ export const getSignedImageUrl = async (key: string) => {
|
||||
|
||||
return isDocker
|
||||
? `${publicS3Endpoint()}/${key}`
|
||||
: s3.getSignedUrl('getObject', params);
|
||||
: s3.getSignedUrl("getObject", params);
|
||||
};
|
||||
|
||||
export const getImageByKey = async (key: string) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @flow
|
||||
import slug from 'slug';
|
||||
import slug from "slug";
|
||||
|
||||
slug.defaults.mode = 'rfc3986';
|
||||
slug.defaults.mode = "rfc3986";
|
||||
|
||||
export default function slugify(text: string): string {
|
||||
return slug(text, {
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
// @flow
|
||||
import crypto from 'crypto';
|
||||
import invariant from 'invariant';
|
||||
import fetch from 'isomorphic-fetch';
|
||||
import { client } from '../redis';
|
||||
import packageInfo from '../../package.json';
|
||||
import crypto from "crypto";
|
||||
import invariant from "invariant";
|
||||
import fetch from "isomorphic-fetch";
|
||||
import { client } from "../redis";
|
||||
import packageInfo from "../../package.json";
|
||||
|
||||
import { User, Team, Collection, Document } from '../models';
|
||||
import { User, Team, Collection, Document } from "../models";
|
||||
|
||||
const UPDATES_URL = 'https://updates.getoutline.com';
|
||||
const UPDATES_KEY = 'UPDATES_KEY';
|
||||
const UPDATES_URL = "https://updates.getoutline.com";
|
||||
const UPDATES_KEY = "UPDATES_KEY";
|
||||
|
||||
export default async () => {
|
||||
invariant(
|
||||
process.env.SECRET_KEY && process.env.URL,
|
||||
'SECRET_KEY or URL env var is not set'
|
||||
"SECRET_KEY or URL env var is not set"
|
||||
);
|
||||
const secret = process.env.SECRET_KEY.slice(0, 6) + process.env.URL;
|
||||
const id = crypto
|
||||
.createHash('sha256')
|
||||
.createHash("sha256")
|
||||
.update(secret)
|
||||
.digest('hex');
|
||||
.digest("hex");
|
||||
|
||||
const [
|
||||
userCount,
|
||||
@@ -45,14 +45,14 @@ export default async () => {
|
||||
},
|
||||
});
|
||||
|
||||
await client.del('UPDATES_KEY');
|
||||
await client.del("UPDATES_KEY");
|
||||
|
||||
try {
|
||||
const response = await fetch(UPDATES_URL, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body,
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// @flow
|
||||
import fs from 'fs';
|
||||
import JSZip from 'jszip';
|
||||
import tmp from 'tmp';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { Attachment, Collection, Document } from '../models';
|
||||
import { getImageByKey } from './s3';
|
||||
import fs from "fs";
|
||||
import JSZip from "jszip";
|
||||
import tmp from "tmp";
|
||||
import * as Sentry from "@sentry/node";
|
||||
import { Attachment, Collection, Document } from "../models";
|
||||
import { getImageByKey } from "./s3";
|
||||
|
||||
async function addToArchive(zip, documents) {
|
||||
for (const doc of documents) {
|
||||
@@ -20,7 +20,7 @@ async function addToArchive(zip, documents) {
|
||||
text = text.replace(attachment.redirectUrl, encodeURI(attachment.key));
|
||||
}
|
||||
|
||||
zip.file(`${document.title || 'Untitled'}.md`, text);
|
||||
zip.file(`${document.title || "Untitled"}.md`, text);
|
||||
|
||||
if (doc.children && doc.children.length) {
|
||||
const folder = zip.folder(document.title);
|
||||
@@ -44,14 +44,14 @@ async function addImageToArchive(zip, key) {
|
||||
|
||||
async function archiveToPath(zip) {
|
||||
return new Promise((resolve, reject) => {
|
||||
tmp.file({ prefix: 'export-', postfix: '.zip' }, (err, path) => {
|
||||
tmp.file({ prefix: "export-", postfix: ".zip" }, (err, path) => {
|
||||
if (err) return reject(err);
|
||||
|
||||
zip
|
||||
.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
|
||||
.generateNodeStream({ type: "nodebuffer", streamFiles: true })
|
||||
.pipe(fs.createWriteStream(path))
|
||||
.on('finish', () => resolve(path))
|
||||
.on('error', reject);
|
||||
.on("finish", () => resolve(path))
|
||||
.on("error", reject);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user