feat: better decryption attempt; upgrade snjs with file size changes

This commit is contained in:
Mo
2022-04-27 09:46:25 -05:00
parent bce8c5fcba
commit d33e48edd8
8 changed files with 97 additions and 112 deletions

View File

@@ -95,15 +95,12 @@ export const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
<div className="text-sm mb-1 break-word">
<span className="vertical-middle">{file.name}</span>
{file.protected && (
<Icon
type="lock-filled"
className="sn-icon--small ml-2 color-neutral vertical-middle"
/>
<Icon type="lock-filled" className="sn-icon--small ml-2 color-neutral vertical-middle" />
)}
</div>
)}
<div className="text-xs color-grey-0">
{file.created_at.toLocaleString()} · {formatSizeToReadableString(file.size)}
{file.created_at.toLocaleString()} · {formatSizeToReadableString(file.decryptedSize)}
</div>
</div>
</div>

View File

@@ -18,14 +18,13 @@ export const FilePreviewInfoPanel: FunctionComponent<Props> = ({ file }) => {
<span className="font-semibold">Type:</span> {file.mimeType}
</div>
<div className="mb-3">
<span className="font-semibold">Size:</span> {formatSizeToReadableString(file.size)}
<span className="font-semibold">Size:</span> {formatSizeToReadableString(file.decryptedSize)}
</div>
<div className="mb-3">
<span className="font-semibold">Created:</span> {file.created_at.toLocaleString()}
</div>
<div className="mb-3">
<span className="font-semibold">Last Modified:</span>{' '}
{file.userModifiedDate.toLocaleString()}
<span className="font-semibold">Last Modified:</span> {file.userModifiedDate.toLocaleString()}
</div>
<div>
<span className="font-semibold">File ID:</span> {file.uuid}

View File

@@ -10,6 +10,7 @@ import {
} from '@/Components/Preferences/PreferencesComponents'
import {
ButtonType,
ClientDisplayableError,
DisplayStringForContentType,
EncryptedItemInterface,
} from '@standardnotes/snjs'
@@ -17,7 +18,9 @@ import { Button } from '@/Components/Button/Button'
import { HorizontalSeparator } from '@/Components/Shared/HorizontalSeparator'
import { useState } from 'preact/hooks'
export const ErroredItems: FunctionComponent<{ appState: AppState }> = observer(({ appState }) => {
type Props = { appState: AppState }
export const ErroredItems: FunctionComponent<Props> = observer(({ appState }: Props) => {
const app = appState.application
const [erroredItems, setErroredItems] = useState(app.items.invalidItems)
@@ -51,6 +54,18 @@ export const ErroredItems: FunctionComponent<{ appState: AppState }> = observer(
setErroredItems(app.items.invalidItems)
}
const attemptDecryption = (item: EncryptedItemInterface): void => {
const errorOrTrue = app.canAttemptDecryptionOfItem(item)
if (errorOrTrue instanceof ClientDisplayableError) {
void app.alertService.showErrorAlert(errorOrTrue)
return
}
app.presentKeyRecoveryWizard()
}
return (
<PreferencesGroup>
<PreferencesSegment>
@@ -84,9 +99,7 @@ export const ErroredItems: FunctionComponent<{ appState: AppState }> = observer(
<>
<div className="flex items-center justify-between">
<div className="flex flex-col">
<Subtitle>{`${getContentTypeDisplay(item)} created on ${
item.createdAtString
}`}</Subtitle>
<Subtitle>{`${getContentTypeDisplay(item)} created on ${item.createdAtString}`}</Subtitle>
<Text>
<div>Item ID: {item.uuid}</div>
<div>Last Modified: {item.updatedAtString}</div>
@@ -97,7 +110,7 @@ export const ErroredItems: FunctionComponent<{ appState: AppState }> = observer(
variant="normal"
label="Attempt decryption"
onClick={() => {
void app.presentKeyRecoveryWizard()
attemptDecryption(item)
}}
/>
<Button

View File

@@ -1,4 +1,3 @@
/* eslint-disable prefer-promise-reject-errors */
import { SNAlertService, ButtonType, sanitizeHtmlString } from '@standardnotes/snjs'
import { SKAlert } from '@standardnotes/stylekit'
@@ -66,10 +65,7 @@ export function alertDialog({
})
}
export class AlertService implements SNAlertService {
/**
* @deprecated use the standalone `alertDialog` function instead
*/
export class AlertService extends SNAlertService {
alert(text: string, title?: string, closeButtonText?: string) {
return alertDialog({ text, title, closeButtonText })
}

View File

@@ -18,9 +18,7 @@ export class FilesState {
let downloadingToastId = ''
try {
const saver = StreamingFileSaver.available()
? new StreamingFileSaver(file.name)
: new ClassicFileSaver()
const saver = StreamingFileSaver.available() ? new StreamingFileSaver(file.name) : new ClassicFileSaver()
const isUsingStreamingSaver = saver instanceof StreamingFileSaver
@@ -110,7 +108,7 @@ export class FilesState {
message: `Uploading file "${file.name}"...`,
})
const operation = await this.application.files.beginNewFileUpload()
const operation = await this.application.files.beginNewFileUpload(file.size)
if (operation instanceof ClientDisplayableError) {
addToast({

View File

@@ -1,10 +1,6 @@
import { confirmDialog } from '@/Services/AlertService'
import { STRING_DELETE_TAG } from '@/Strings'
import {
MAX_MENU_SIZE_MULTIPLIER,
MENU_MARGIN_FROM_APP_BORDER,
SMART_TAGS_FEATURE_NAME,
} from '@/Constants'
import { MAX_MENU_SIZE_MULTIPLIER, MENU_MARGIN_FROM_APP_BORDER, SMART_TAGS_FEATURE_NAME } from '@/Constants'
import {
ComponentAction,
ContentType,
@@ -46,11 +42,7 @@ const tagSiblings = (application: SNApplication, tag: SNTag): SNTag[] => {
return withoutCurrentTag(rootTags(application))
}
const isValidFutureSiblings = (
application: SNApplication,
futureSiblings: SNTag[],
tag: SNTag,
): boolean => {
const isValidFutureSiblings = (application: SNApplication, futureSiblings: SNTag[], tag: SNTag): boolean => {
const siblingWithSameName = futureSiblings.find((otherTag) => otherTag.title === tag.title)
if (siblingWithSameName) {
@@ -83,11 +75,7 @@ export class TagsState {
private readonly tagsCountsState: TagsCountsState
constructor(
private application: WebApplication,
appEventListeners: (() => void)[],
private features: FeaturesState,
) {
constructor(private application: WebApplication, appEventListeners: (() => void)[], private features: FeaturesState) {
this.tagsCountsState = new TagsCountsState(this.application)
this.selected_ = undefined
@@ -138,31 +126,28 @@ export class TagsState {
})
appEventListeners.push(
this.application.streamItems(
[ContentType.Tag, ContentType.SmartView],
({ changed, removed }) => {
runInAction(() => {
this.tags = this.application.items.getDisplayableItems<SNTag>(ContentType.Tag)
this.application.streamItems([ContentType.Tag, ContentType.SmartView], ({ changed, removed }) => {
runInAction(() => {
this.tags = this.application.items.getDisplayableItems<SNTag>(ContentType.Tag)
this.smartViews = this.application.items.getSmartViews()
this.smartViews = this.application.items.getSmartViews()
const selectedTag = this.selected_
const selectedTag = this.selected_
if (selectedTag && !isSystemView(selectedTag as SmartView)) {
if (FindItem(removed, selectedTag.uuid)) {
this.selected_ = this.smartViews[0]
}
const updated = FindItem(changed, selectedTag.uuid)
if (updated) {
this.selected_ = updated as AnyTag
}
} else {
if (selectedTag && !isSystemView(selectedTag as SmartView)) {
if (FindItem(removed, selectedTag.uuid)) {
this.selected_ = this.smartViews[0]
}
})
},
),
const updated = FindItem(changed, selectedTag.uuid)
if (updated) {
this.selected_ = updated as AnyTag
}
} else {
this.selected_ = this.smartViews[0]
}
})
}),
)
appEventListeners.push(
@@ -170,7 +155,10 @@ export class TagsState {
if (!tagUuid) {
this.setAllNotesCount(this.application.items.allCountableNotesCount())
} else {
this.tagsCountsState.update([this.application.items.findItem(tagUuid) as SNTag])
const tag = this.application.items.findItem<SNTag>(tagUuid)
if (tag) {
this.tagsCountsState.update([tag])
}
}
}),
)
@@ -314,8 +302,7 @@ export class TagsState {
return
}
const futureParent =
futureParentUuid && (this.application.items.findItem(futureParentUuid) as SNTag)
const futureParent = futureParentUuid && (this.application.items.findItem(futureParentUuid) as SNTag)
if (!futureParent) {
const futureSiblings = rootTags(this.application)
@@ -399,8 +386,7 @@ export class TagsState {
}
public async createNewTemplate() {
const isAlreadyEditingATemplate =
this.editing_ && this.application.items.isTemplateItem(this.editing_)
const isAlreadyEditingATemplate = this.editing_ && this.application.items.isTemplateItem(this.editing_)
if (isAlreadyEditingATemplate) {
return
@@ -439,9 +425,7 @@ export class TagsState {
const isTemplateChange = this.application.items.isTemplateItem(tag)
const siblings = tag instanceof SNTag ? tagSiblings(this.application, tag) : []
const hasDuplicatedTitle = siblings.some(
(other) => other.title.toLowerCase() === newTitle.toLowerCase(),
)
const hasDuplicatedTitle = siblings.some((other) => other.title.toLowerCase() === newTitle.toLowerCase())
runInAction(() => {
this.editing_ = undefined
@@ -458,9 +442,7 @@ export class TagsState {
if (isTemplateChange) {
this.undoCreateNewTag()
}
this.application.alertService
?.alert('A tag with this name already exists.')
.catch(console.error)
this.application.alertService?.alert('A tag with this name already exists.').catch(console.error)
return
}