-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into chore/assets-endpo…
…ints-to-ts
- Loading branch information
Showing
318 changed files
with
8,075 additions
and
10,105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: 'Auto label QA' | ||
on: | ||
pull_request: | ||
types: [opened, synchronize, labeled, unlabeled] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: ggazzo/gh-action-auto-label@beta-5 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { IEmojiCustom, ILivechatDepartmentRecord } from '@rocket.chat/core-typings'; | ||
import { FilterQuery, SortOptionObject } from 'mongodb'; | ||
|
||
import { EmojiCustom } from '../../../models/server/raw'; | ||
|
||
export async function findEmojisCustom({ | ||
query = {}, | ||
pagination: { offset, count, sort }, | ||
}: { | ||
query: FilterQuery<ILivechatDepartmentRecord>; | ||
pagination: { offset: number; count: number; sort: SortOptionObject<IEmojiCustom> }; | ||
}): Promise<{ | ||
emojis: IEmojiCustom[]; | ||
count: number; | ||
offset: any; | ||
total: number; | ||
}> { | ||
const cursor = EmojiCustom.find(query, { | ||
sort: sort || { name: 1 }, | ||
skip: offset, | ||
limit: count, | ||
}); | ||
|
||
const total = await cursor.count(); | ||
|
||
const emojis = await cursor.toArray(); | ||
|
||
return { | ||
emojis, | ||
count: emojis.length, | ||
offset, | ||
total, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,90 @@ | ||
import { Readable } from 'stream'; | ||
|
||
import { Meteor } from 'meteor/meteor'; | ||
import type { Request } from 'express'; | ||
import busboy from 'busboy'; | ||
import { Request } from 'express'; | ||
import { ValidateFunction } from 'ajv'; | ||
|
||
export interface IFormDataFields { | ||
file: any; | ||
type UploadResult = { | ||
file: Readable; | ||
filename: string; | ||
encoding: string; | ||
mimetype: string; | ||
fileBuffer: Buffer; | ||
} | ||
|
||
export interface IFormDataUpload { | ||
[key: string]: IFormDataFields | any; | ||
} | ||
}; | ||
|
||
export const getUploadFormData = async ({ request }: { request: Request }): Promise<IFormDataUpload> => | ||
new Promise<IFormDataUpload>((resolve, reject) => { | ||
export const getUploadFormData = async <T extends string, K, V extends ValidateFunction<K>>( | ||
{ request }: { request: Request }, | ||
options: { | ||
field?: T; | ||
validate?: V; | ||
} = {}, | ||
): Promise< | ||
[ | ||
UploadResult, | ||
K extends unknown | ||
? { | ||
[k: string]: string; | ||
} | ||
: K, | ||
T, | ||
] | ||
> => | ||
new Promise((resolve, reject) => { | ||
const bb = busboy({ headers: request.headers, defParamCharset: 'utf8' }); | ||
const fields: { [K: string]: string } = Object.create(null); | ||
|
||
const fields: IFormDataUpload = {}; | ||
let uploadedFile: UploadResult | undefined; | ||
|
||
bb.on('file', (fieldname: string, file: any, { filename, encoding, mimeType: mimetype }: Record<string, any>) => { | ||
const fileData: any[] = []; | ||
let assetName: T | undefined; | ||
|
||
file.on('data', (data: any) => fileData.push(data)); | ||
bb.on( | ||
'file', | ||
( | ||
fieldname: string, | ||
file: Readable, | ||
{ filename, encoding, mimeType: mimetype }: { filename: string; encoding: string; mimeType: string }, | ||
) => { | ||
const fileData: Uint8Array[] = []; | ||
|
||
file.on('end', () => { | ||
if (fields.hasOwnProperty(fieldname)) { | ||
return reject('Just 1 file is allowed'); | ||
} | ||
file.on('data', (data: any) => fileData.push(data)); | ||
|
||
fields[fieldname] = { | ||
file, | ||
filename, | ||
encoding, | ||
mimetype, | ||
fileBuffer: Buffer.concat(fileData), | ||
}; | ||
}); | ||
}); | ||
file.on('end', () => { | ||
if (uploadedFile) { | ||
return reject('Just 1 file is allowed'); | ||
} | ||
if (options.field && fieldname !== options.field) { | ||
return reject(new Meteor.Error('invalid-field')); | ||
} | ||
uploadedFile = { | ||
file, | ||
filename, | ||
encoding, | ||
mimetype, | ||
fileBuffer: Buffer.concat(fileData), | ||
}; | ||
|
||
bb.on('field', (fieldname: string, value: any) => { | ||
assetName = fieldname as T; | ||
}); | ||
}, | ||
); | ||
|
||
bb.on('field', (fieldname, value) => { | ||
fields[fieldname] = value; | ||
}); | ||
|
||
bb.on('finish', () => resolve(fields)); | ||
bb.on('finish', () => { | ||
if (!uploadedFile || !assetName) { | ||
return reject('No file uploaded'); | ||
} | ||
if (options.validate === undefined) { | ||
return resolve([uploadedFile, fields, assetName]); | ||
} | ||
if (!options.validate(fields)) { | ||
return reject(`Invalid fields${options.validate.errors?.join(', ')}`); | ||
} | ||
return resolve([uploadedFile, fields, assetName]); | ||
}); | ||
|
||
request.pipe(bb); | ||
}); |
Oops, something went wrong.