26 lines
983 B
TypeScript
26 lines
983 B
TypeScript
import type { PreparedHotlinkUploadRequest } from '@/types/upload/PreparedHotlinkUploadRequest';
|
|
import type { UploadOptionsRequest } from '@/types/upload/UploadOptionsRequest';
|
|
import { hashHotlinkAccessToken } from '@/utils/crypto/hashHotlinkAccessToken';
|
|
import { bytesToBase64 } from '@/utils/encoding/bytesToBase64';
|
|
import { encryptHotlinkUpload } from '@/utils/upload/encryptHotlinkUpload';
|
|
|
|
export const prepareHotlinkUploadRequest = async (
|
|
plaintext: Uint8Array,
|
|
mimeType: string,
|
|
options: UploadOptionsRequest
|
|
): Promise<PreparedHotlinkUploadRequest> => {
|
|
const encrypted = await encryptHotlinkUpload(plaintext);
|
|
const accessTokenHash = await hashHotlinkAccessToken(encrypted.secret);
|
|
|
|
return {
|
|
secret: encrypted.secret,
|
|
request: {
|
|
...options,
|
|
iv: bytesToBase64(encrypted.iv),
|
|
ciphertext: bytesToBase64(encrypted.ciphertext),
|
|
mimeType,
|
|
accessTokenHash
|
|
}
|
|
};
|
|
};
|