Spruce
This commit is contained in:
parent
51a1c77720
commit
0566d2ee93
11 changed files with 48 additions and 56 deletions
|
@ -1,20 +0,0 @@
|
|||
export enum FILE_TYPE {
|
||||
IMAGE,
|
||||
VIDEO,
|
||||
LIVE_PHOTO,
|
||||
OTHERS,
|
||||
}
|
||||
|
||||
export const RAW_FORMATS = [
|
||||
"heic",
|
||||
"rw2",
|
||||
"tiff",
|
||||
"arw",
|
||||
"cr3",
|
||||
"cr2",
|
||||
"raf",
|
||||
"nef",
|
||||
"psd",
|
||||
"dng",
|
||||
"tif",
|
||||
];
|
|
@ -1,6 +1,20 @@
|
|||
import { FILE_TYPE } from "constants/file";
|
||||
import { FILE_TYPE } from "@/media/file";
|
||||
import { FileTypeInfo } from "types/upload";
|
||||
|
||||
export const RAW_FORMATS = [
|
||||
"heic",
|
||||
"rw2",
|
||||
"tiff",
|
||||
"arw",
|
||||
"cr3",
|
||||
"cr2",
|
||||
"raf",
|
||||
"nef",
|
||||
"psd",
|
||||
"dng",
|
||||
"tif",
|
||||
];
|
||||
|
||||
// list of format that were missed by type-detection for some files.
|
||||
export const WHITELISTED_FILE_FORMATS: FileTypeInfo[] = [
|
||||
{ fileType: FILE_TYPE.IMAGE, exactType: "jpeg", mimeType: "image/jpeg" },
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import log from "@/next/log";
|
||||
import PairedSuccessfullyOverlay from "components/PairedSuccessfullyOverlay";
|
||||
import { PhotoAuditorium } from "components/PhotoAuditorium";
|
||||
import { FILE_TYPE } from "constants/file";
|
||||
import { FILE_TYPE } from "@/media/file";
|
||||
import { useRouter } from "next/router";
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
|
|
|
@ -2,7 +2,7 @@ import ComlinkCryptoWorker from "@ente/shared/crypto";
|
|||
import { CustomError } from "@ente/shared/error";
|
||||
import HTTPService from "@ente/shared/network/HTTPService";
|
||||
import { getCastFileURL } from "@ente/shared/network/api";
|
||||
import { FILE_TYPE } from "constants/file";
|
||||
import { FILE_TYPE } from "@/media/file";
|
||||
import { EnteFile } from "types/file";
|
||||
import { generateStreamFromArrayBuffer } from "utils/file";
|
||||
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
import { convertBytesToHumanReadable } from "@/next/file";
|
||||
import log from "@/next/log";
|
||||
|
||||
export async function getUint8ArrayView(file: Blob): Promise<Uint8Array> {
|
||||
try {
|
||||
return new Uint8Array(await file.arrayBuffer());
|
||||
} catch (e) {
|
||||
log.error(
|
||||
`Failed to read file blob of size ${convertBytesToHumanReadable(file.size)}`,
|
||||
e,
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
|
@ -1,14 +1,13 @@
|
|||
import { nameAndExtension } from "@/next/file";
|
||||
import { FILE_TYPE } from "@/media/file";
|
||||
import { convertBytesToHumanReadable, nameAndExtension } from "@/next/file";
|
||||
import log from "@/next/log";
|
||||
import { CustomError } from "@ente/shared/error";
|
||||
import { FILE_TYPE } from "constants/file";
|
||||
import {
|
||||
KNOWN_NON_MEDIA_FORMATS,
|
||||
WHITELISTED_FILE_FORMATS,
|
||||
} from "constants/upload";
|
||||
import FileType from "file-type";
|
||||
import { FileTypeInfo } from "types/upload";
|
||||
import { getUint8ArrayView } from "./readerService";
|
||||
|
||||
const TYPE_VIDEO = "video";
|
||||
const TYPE_IMAGE = "image";
|
||||
|
@ -66,6 +65,18 @@ async function extractFileType(file: File) {
|
|||
return getFileTypeFromBuffer(fileDataChunk);
|
||||
}
|
||||
|
||||
export async function getUint8ArrayView(file: Blob): Promise<Uint8Array> {
|
||||
try {
|
||||
return new Uint8Array(await file.arrayBuffer());
|
||||
} catch (e) {
|
||||
log.error(
|
||||
`Failed to read file blob of size ${convertBytesToHumanReadable(file.size)}`,
|
||||
e,
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async function getFileTypeFromBuffer(buffer: Uint8Array) {
|
||||
const result = await FileType.fromBuffer(buffer);
|
||||
if (!result?.mime) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { FILE_TYPE } from "constants/file";
|
||||
import { FILE_TYPE } from "@/media/file";
|
||||
|
||||
export interface Metadata {
|
||||
title: string;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { FILE_TYPE } from "@/media/file";
|
||||
import { decodeLivePhoto } from "@/media/live-photo";
|
||||
import log from "@/next/log";
|
||||
import ComlinkCryptoWorker from "@ente/shared/crypto";
|
||||
import { FILE_TYPE, RAW_FORMATS } from "constants/file";
|
||||
import { RAW_FORMATS } from "constants/upload";
|
||||
import CastDownloadManager from "services/castDownloadManager";
|
||||
import { getFileType } from "services/typeDetectionService";
|
||||
import {
|
||||
|
@ -103,18 +104,6 @@ export function isRawFileFromFileName(fileName: string) {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Note: File name for local EnteFile objects]
|
||||
*
|
||||
* The title property in a file's metadata is the original file's name. The
|
||||
* metadata of a file cannot be edited. So if later on the file's name is
|
||||
* changed, then the edit is stored in the `editedName` property of the public
|
||||
* metadata of the file.
|
||||
*
|
||||
* This function merges these edits onto the file object that we use locally.
|
||||
* Effectively, post this step, the file's metadata.title can be used in lieu of
|
||||
* its filename.
|
||||
*/
|
||||
export function mergeMetadata(files: EnteFile[]): EnteFile[] {
|
||||
return files.map((file) => {
|
||||
if (file.pubMagicMetadata?.data.editedTime) {
|
|
@ -8,6 +8,7 @@ import {
|
|||
tryToParseDateTime,
|
||||
validateAndGetCreationUnixTimeInMicroSeconds,
|
||||
} from "@ente/shared/time";
|
||||
import type { DataStream } from "@ente/shared/utils/data-stream";
|
||||
import { Remote } from "comlink";
|
||||
import { FILE_TYPE } from "constants/file";
|
||||
import { FILE_READER_CHUNK_SIZE, NULL_LOCATION } from "constants/upload";
|
||||
|
@ -29,7 +30,6 @@ import {
|
|||
type ParsedMetadataJSON,
|
||||
} from "./takeout";
|
||||
import { getFileName } from "./uploadService";
|
||||
import type { DataStream } from "@ente/shared/utils/data-stream";
|
||||
|
||||
const EXIF_TAGS_NEEDED = [
|
||||
"DateTimeOriginal",
|
||||
|
|
|
@ -7,6 +7,7 @@ import { CustomErrorMessage } from "@/next/types/ipc";
|
|||
import { DedicatedCryptoWorker } from "@ente/shared/crypto/internal/crypto.worker";
|
||||
import { EncryptionResult } from "@ente/shared/crypto/types";
|
||||
import { CustomError, handleUploadError } from "@ente/shared/error";
|
||||
import { isDataStream, type DataStream } from "@ente/shared/utils/data-stream";
|
||||
import { Remote } from "comlink";
|
||||
import { FILE_TYPE } from "constants/file";
|
||||
import {
|
||||
|
@ -59,7 +60,6 @@ import {
|
|||
} from "./thumbnail";
|
||||
import uploadCancelService from "./uploadCancelService";
|
||||
import UploadHttpClient from "./uploadHttpClient";
|
||||
import { isDataStream, type DataStream } from "@ente/shared/utils/data-stream";
|
||||
|
||||
/** Upload files to cloud storage */
|
||||
class UploadService {
|
||||
|
|
|
@ -441,6 +441,18 @@ export function isSharedFile(user: User, file: EnteFile) {
|
|||
return file.ownerID !== user.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Note: File name for local EnteFile objects]
|
||||
*
|
||||
* The title property in a file's metadata is the original file's name. The
|
||||
* metadata of a file cannot be edited. So if later on the file's name is
|
||||
* changed, then the edit is stored in the `editedName` property of the public
|
||||
* metadata of the file.
|
||||
*
|
||||
* This function merges these edits onto the file object that we use locally.
|
||||
* Effectively, post this step, the file's metadata.title can be used in lieu of
|
||||
* its filename.
|
||||
*/
|
||||
export function mergeMetadata(files: EnteFile[]): EnteFile[] {
|
||||
return files.map((file) => {
|
||||
if (file.pubMagicMetadata?.data.editedTime) {
|
||||
|
|
Loading…
Add table
Reference in a new issue