mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
Merge pull request #18289 from overleaf/ac-ar-eslint-return-await
Add ESLint rule @typescript-eslint/return-await to backend services GitOrigin-RevId: 75e3e32597827fcc852e69d479515fc72e8f45e4
This commit is contained in:
@@ -80,7 +80,13 @@ class AccessTokenSchemeWithGenericKeyFn extends AbstractAccessTokenScheme {
|
||||
class AccessTokenSchemeV3 extends AccessTokenSchemeWithGenericKeyFn {
|
||||
async keyFn(salt) {
|
||||
const optionalInfo = ''
|
||||
return cryptoHkdf('sha512', this.cipherPassword, salt, optionalInfo, 32)
|
||||
return await cryptoHkdf(
|
||||
'sha512',
|
||||
this.cipherPassword,
|
||||
salt,
|
||||
optionalInfo,
|
||||
32
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ const DRY_RUN = !process.argv.includes('--dry-run=false')
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
async function reEncryptTokens(accessTokenEncryptor, encryptedJson) {
|
||||
return new Promise((resolve, reject) => {
|
||||
return await new Promise((resolve, reject) => {
|
||||
accessTokenEncryptor.decryptToJson(encryptedJson, (err, json) => {
|
||||
if (err) return reject(err)
|
||||
accessTokenEncryptor.encryptJson(json, (err, reEncryptedJson) => {
|
||||
|
||||
@@ -239,6 +239,11 @@ async function discardResponseBody(response) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {import('node-fetch').Response} Response
|
||||
*
|
||||
* @param {Response} response
|
||||
*/
|
||||
async function maybeGetResponseBody(response) {
|
||||
try {
|
||||
return await response.text()
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"author": "Overleaf (https://www.overleaf.com)",
|
||||
"license": "AGPL-3.0-only",
|
||||
"devDependencies": {
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
"body-parser": "^1.20.2",
|
||||
"chai": "^4.3.6",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
|
||||
@@ -42,7 +42,7 @@ module.exports = class GcsPersistor extends AbstractPersistor {
|
||||
}
|
||||
|
||||
async sendFile(bucketName, key, fsPath) {
|
||||
return this.sendStream(bucketName, key, fs.createReadStream(fsPath))
|
||||
return await this.sendStream(bucketName, key, fs.createReadStream(fsPath))
|
||||
}
|
||||
|
||||
async sendStream(bucketName, key, readStream, opts = {}) {
|
||||
|
||||
@@ -17,55 +17,65 @@ const { NotFoundError, WriteError } = require('./Errors')
|
||||
// }
|
||||
|
||||
module.exports = class MigrationPersistor extends AbstractPersistor {
|
||||
/**
|
||||
* @param {AbstractPersistor} primaryPersistor
|
||||
* @param {AbstractPersistor} fallbackPersistor
|
||||
* @param settings
|
||||
*/
|
||||
constructor(primaryPersistor, fallbackPersistor, settings) {
|
||||
super()
|
||||
|
||||
/**
|
||||
* @type {AbstractPersistor}
|
||||
*/
|
||||
this.primaryPersistor = primaryPersistor
|
||||
/**
|
||||
* @type {AbstractPersistor}
|
||||
*/
|
||||
this.fallbackPersistor = fallbackPersistor
|
||||
this.settings = settings
|
||||
}
|
||||
|
||||
async sendFile(...args) {
|
||||
return this.primaryPersistor.sendFile(...args)
|
||||
return await this.primaryPersistor.sendFile(...args)
|
||||
}
|
||||
|
||||
async sendStream(...args) {
|
||||
return this.primaryPersistor.sendStream(...args)
|
||||
return await this.primaryPersistor.sendStream(...args)
|
||||
}
|
||||
|
||||
async getRedirectUrl(...args) {
|
||||
return this.primaryPersistor.getRedirectUrl(...args)
|
||||
return await this.primaryPersistor.getRedirectUrl(...args)
|
||||
}
|
||||
|
||||
async getObjectMd5Hash(...args) {
|
||||
return this._runWithFallback('getObjectMd5Hash', ...args)
|
||||
return await this._runWithFallback('getObjectMd5Hash', ...args)
|
||||
}
|
||||
|
||||
async checkIfObjectExists(...args) {
|
||||
return this._runWithFallback('checkIfObjectExists', ...args)
|
||||
return await this._runWithFallback('checkIfObjectExists', ...args)
|
||||
}
|
||||
|
||||
async getObjectSize(...args) {
|
||||
return this._runWithFallback('getObjectSize', ...args)
|
||||
return await this._runWithFallback('getObjectSize', ...args)
|
||||
}
|
||||
|
||||
async directorySize(...args) {
|
||||
return this._runWithFallback('directorySize', ...args)
|
||||
return await this._runWithFallback('directorySize', ...args)
|
||||
}
|
||||
|
||||
async deleteObject(...args) {
|
||||
return this._runOnBoth('deleteObject', ...args)
|
||||
return await this._runOnBoth('deleteObject', ...args)
|
||||
}
|
||||
|
||||
async deleteDirectory(...args) {
|
||||
return this._runOnBoth('deleteDirectory', ...args)
|
||||
return await this._runOnBoth('deleteDirectory', ...args)
|
||||
}
|
||||
|
||||
async getObjectStream(bucket, key, opts = {}) {
|
||||
const shouldCopy = this.settings.copyOnMiss && !opts.start && !opts.end
|
||||
|
||||
try {
|
||||
// 'return await' so we catch NotFoundError before returning
|
||||
return await this.primaryPersistor.getObjectStream(bucket, key, opts)
|
||||
} catch (err) {
|
||||
if (err instanceof NotFoundError) {
|
||||
@@ -140,7 +150,7 @@ module.exports = class MigrationPersistor extends AbstractPersistor {
|
||||
})
|
||||
}
|
||||
// copy from sourceKey -> destKey
|
||||
return this._copyStreamFromFallbackAndVerify(
|
||||
return await this._copyStreamFromFallbackAndVerify(
|
||||
copyStream,
|
||||
fallbackBucket,
|
||||
bucket,
|
||||
@@ -217,9 +227,14 @@ module.exports = class MigrationPersistor extends AbstractPersistor {
|
||||
])
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {keyof AbstractPersistor} methodName
|
||||
* @param bucket
|
||||
* @param key
|
||||
* @param moreArgs
|
||||
*/
|
||||
async _runWithFallback(methodName, bucket, key, ...moreArgs) {
|
||||
try {
|
||||
// 'return await' so we catch NotFoundError before returning
|
||||
return await this.primaryPersistor[methodName](bucket, key, ...moreArgs)
|
||||
} catch (err) {
|
||||
if (err instanceof NotFoundError) {
|
||||
@@ -241,7 +256,7 @@ module.exports = class MigrationPersistor extends AbstractPersistor {
|
||||
Logger.warn({ err }, 'failed to copy file from fallback')
|
||||
})
|
||||
}
|
||||
return this.fallbackPersistor[methodName](
|
||||
return await this.fallbackPersistor[methodName](
|
||||
fallbackBucket,
|
||||
key,
|
||||
...moreArgs
|
||||
|
||||
@@ -24,7 +24,7 @@ module.exports = class S3Persistor extends AbstractPersistor {
|
||||
}
|
||||
|
||||
async sendFile(bucketName, key, fsPath) {
|
||||
return this.sendStream(bucketName, key, fs.createReadStream(fsPath))
|
||||
return await this.sendStream(bucketName, key, fs.createReadStream(fsPath))
|
||||
}
|
||||
|
||||
async sendStream(bucketName, key, readStream, opts = {}) {
|
||||
@@ -231,7 +231,7 @@ module.exports = class S3Persistor extends AbstractPersistor {
|
||||
if (this.settings.Metrics) {
|
||||
this.settings.Metrics.inc('s3.md5Download')
|
||||
}
|
||||
return PersistorHelper.calculateStreamMd5(
|
||||
return await PersistorHelper.calculateStreamMd5(
|
||||
await this.getObjectStream(bucketName, key)
|
||||
)
|
||||
} catch (err) {
|
||||
|
||||
@@ -225,7 +225,7 @@ describe('MigrationPersistorTests', function () {
|
||||
newPersistor(false),
|
||||
Settings
|
||||
)
|
||||
return expect(
|
||||
await expect(
|
||||
migrationPersistor.getObjectStream(bucket, key)
|
||||
).to.eventually.be.rejected.and.be.an.instanceOf(Errors.NotFoundError)
|
||||
})
|
||||
@@ -322,7 +322,7 @@ describe('MigrationPersistorTests', function () {
|
||||
describe('when the primary persistor throws an error', function () {
|
||||
it('returns the error', async function () {
|
||||
primaryPersistor.sendStream.rejects(notFoundError)
|
||||
return expect(
|
||||
await expect(
|
||||
migrationPersistor.sendStream(bucket, key, fileStream)
|
||||
).to.eventually.be.rejected.and.be.an.instanceOf(Errors.NotFoundError)
|
||||
})
|
||||
|
||||
@@ -155,7 +155,7 @@ class LazyStringFileData extends FileData {
|
||||
}
|
||||
const eager = await this.toEager(blobStore)
|
||||
this.operations.length = 0
|
||||
return eager.store(blobStore)
|
||||
return await eager.store(blobStore)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ class History {
|
||||
assert.maybe.array.of.instance(changes, Change, 'bad changes')
|
||||
|
||||
this.snapshot = snapshot
|
||||
/** @type {Array<Change>} */
|
||||
this.changes = changes || []
|
||||
}
|
||||
|
||||
@@ -113,6 +114,9 @@ class History {
|
||||
async store(blobStore, concurrency) {
|
||||
assert.maybe.number(concurrency, 'bad concurrency')
|
||||
|
||||
/**
|
||||
* @param {Change} change
|
||||
*/
|
||||
async function storeChange(change) {
|
||||
return await change.store(blobStore, concurrency)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user