-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into new/device-management
- Loading branch information
Showing
91 changed files
with
3,543 additions
and
3,197 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
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 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,90 @@ | ||
import { Readable } from 'stream'; | ||
|
||
import { Meteor } from 'meteor/meteor'; | ||
import type { Request } from 'express'; | ||
import busboy from 'busboy'; | ||
import { ValidateFunction } from 'ajv'; | ||
|
||
type UploadResult = { | ||
file: Readable; | ||
filename: string; | ||
encoding: string; | ||
mimetype: string; | ||
fileBuffer: Buffer; | ||
}; | ||
|
||
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); | ||
|
||
let uploadedFile: UploadResult | undefined; | ||
|
||
let assetName: T | undefined; | ||
|
||
bb.on( | ||
'file', | ||
( | ||
fieldname: string, | ||
file: Readable, | ||
{ filename, encoding, mimeType: mimetype }: { filename: string; encoding: string; mimeType: string }, | ||
) => { | ||
const fileData: Uint8Array[] = []; | ||
|
||
file.on('data', (data: any) => fileData.push(data)); | ||
|
||
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), | ||
}; | ||
|
||
assetName = fieldname as T; | ||
}); | ||
}, | ||
); | ||
|
||
bb.on('field', (fieldname, value) => { | ||
fields[fieldname] = value; | ||
}); | ||
|
||
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); | ||
}); |
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
Oops, something went wrong.