refactor: use correct endpoint when uploading file to shared vault note

This commit is contained in:
Aman Harwara
2023-08-24 15:54:47 +05:30
parent fcaaf549b8
commit 999bbde1b0
5 changed files with 31 additions and 11 deletions

View File

@@ -350,6 +350,7 @@ export class WebDependencies extends DependencyContainer {
this.get<FilePreviewModalController>(Web_TYPES.FilePreviewModalController),
this.get<ArchiveManager>(Web_TYPES.ArchiveManager),
this.get<VaultDisplayService>(Web_TYPES.VaultDisplayService),
application.vaults,
application.items,
application.files,
application.mutator,

View File

@@ -3,7 +3,7 @@ import { usePremiumModal } from '@/Hooks/usePremiumModal'
import { classNames } from '@standardnotes/utils'
import { isHandlingFileDrag } from '@/Utils/DragTypeCheck'
import { StreamingFileReader } from '@standardnotes/filepicker'
import { FileItem } from '@standardnotes/snjs'
import { FileItem, SNNote } from '@standardnotes/snjs'
import { useMemo, useState, createContext, ReactNode, useRef, useCallback, useEffect, useContext, memo } from 'react'
import Portal from './Portal/Portal'
import { ElementIds } from '@/Constants/ElementIDs'
@@ -11,6 +11,7 @@ import { ElementIds } from '@/Constants/ElementIDs'
type FileDragTargetData = {
tooltipText: string
callback: (files: FileItem) => void
note?: SNNote
}
type FileDnDContextData = {
@@ -200,15 +201,17 @@ const FileDragNDropProvider = ({ application, children }: Props) => {
return
}
const uploadedFile = await application.filesController.uploadNewFile(fileOrHandle)
const dragTarget = closestDragTarget ? dragTargets.current.get(closestDragTarget) : undefined
const uploadedFile = await application.filesController.uploadNewFile(fileOrHandle, {
note: dragTarget?.note,
})
if (!uploadedFile) {
return
}
if (closestDragTarget && dragTargets.current.has(closestDragTarget)) {
dragTargets.current.get(closestDragTarget)?.callback(uploadedFile)
}
dragTarget?.callback(uploadedFile)
})
dragCounter.current = 0

View File

@@ -9,7 +9,7 @@ import Icon from '../Icon/Icon'
import DecoratedInput from '../Input/DecoratedInput'
import LinkedItemSearchResults from './LinkedItemSearchResults'
import { LinkedItemsSectionItem } from './LinkedItemsSectionItem'
import { DecryptedItem } from '@standardnotes/snjs'
import { DecryptedItem, SNNote } from '@standardnotes/snjs'
import { useItemLinks } from '@/Hooks/useItemLinks'
import { mergeRefs } from '@/Hooks/mergeRefs'
@@ -41,7 +41,7 @@ const LinkedItemsPanel = ({ item }: { item: DecryptedItem }) => {
return
}
void application.filesController.selectAndUploadNewFiles((file) => {
void application.filesController.selectAndUploadNewFiles(item instanceof SNNote ? item : undefined, (file) => {
void linkItems(item, file)
})
}

View File

@@ -29,6 +29,7 @@ const NoteViewFileDropTarget = ({ note, linkingController, noteViewElement, file
})
filesController.notifyObserversOfUploadedFileLinkingToCurrentNote(uploadedFile.uuid)
},
note,
})
}

View File

@@ -35,7 +35,9 @@ import {
MutatorClientInterface,
Platform,
ProtectionsClientInterface,
SNNote,
SyncServiceInterface,
VaultServiceInterface,
} from '@standardnotes/snjs'
import { addToast, dismissToast, ToastType, updateToast } from '@standardnotes/toast'
import { action, makeObservable, observable, reaction } from 'mobx'
@@ -80,6 +82,7 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
private filePreviewModalController: FilePreviewModalController,
private archiveService: ArchiveManager,
private vaultDisplayService: VaultDisplayServiceInterface,
private vaults: VaultServiceInterface,
private items: ItemManagerInterface,
private files: FilesClientInterface,
private mutator: MutatorClientInterface,
@@ -369,14 +372,16 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
return false
}
public async selectAndUploadNewFiles(callback?: (file: FileItem) => void) {
public async selectAndUploadNewFiles(note?: SNNote, callback?: (file: FileItem) => void) {
const selectedFiles = await this.reader.selectFiles()
selectedFiles.forEach(async (file) => {
if (this.alertIfFileExceedsSizeLimit(file)) {
return
}
const uploadedFile = await this.uploadNewFile(file)
const uploadedFile = await this.uploadNewFile(file, {
note,
})
if (uploadedFile && callback) {
callback(uploadedFile)
}
@@ -385,7 +390,15 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
public async uploadNewFile(
fileOrHandle: File | FileSystemFileHandle,
showToast = true,
{
showToast,
note,
}: {
showToast?: boolean
note?: SNNote
} = {
showToast: true,
},
): Promise<FileItem | undefined> {
let toastId: string | undefined
@@ -407,9 +420,11 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
return
}
const vaultForNote = note ? this.vaults.getItemVault(note) : undefined
const operation = await this.files.beginNewFileUpload(
fileToUpload.size,
this.vaultDisplayService.exclusivelyShownVault,
vaultForNote || this.vaultDisplayService.exclusivelyShownVault,
)
if (operation instanceof ClientDisplayableError) {