feat: cleanup old hashtags

This commit is contained in:
Michal Szczepanski 2023-09-27 07:05:35 +02:00
parent 52978a2892
commit b938e9fb78
14 changed files with 68 additions and 32 deletions

View File

@ -43,8 +43,7 @@ export class PageNoteUpdateCommand implements ICommand<void> {
const newData: ObjNoteDataDto = {
title: this.title,
description: this.description,
words: Array.from(words),
hashtags: this.obj.data.data.hashtags
words: Array.from(words)
};
this.obj.data.hash = fnSha256Object({ ...newData, url: this.obj.data.url, dt });

View File

@ -49,8 +49,7 @@ export class PdfAddCommand implements ICommand<Promise<void>> {
const pdfData: Omit<ObjPdfDataDto, 'hash'> = {
screenshot,
rawUrl: this.value.url,
url,
hashtags: []
url
};
const pdfDataHash = fnSha256Object(pdfData);
const data: ObjPdfDto = {

View File

@ -0,0 +1,24 @@
/*
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
* Copyright (c) 2023 Michal Szczepanski.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export interface ObjHashtagList {
hashtags: ObjHashtag[];
hash: string;
}
export interface ObjHashtag {
value: string;
}

View File

@ -29,5 +29,5 @@ export interface ObjNoteDataDto {
title: string;
description: string;
words: string[];
hashtags: string[];
hashtags?: string[];
}

View File

@ -25,6 +25,6 @@ export interface ObjPdfDataDto {
screenshot: string;
rawUrl: string;
url: ObjUrlDto;
hashtags: string[];
hashtags?: string[];
hash: string;
}

View File

@ -27,7 +27,7 @@ export interface PageSnapshotInfoDto {
url: ObjUrlDto;
title: string;
words: string[];
hashtags: string[];
hashtags?: string[];
}
export interface PageSnapshotDataDto {

View File

@ -84,8 +84,7 @@ export class ContentPageSnapshotCreateCommand implements ICommand<Promise<PageSn
const info: Partial<PageSnapshotInfoDto> = {
title,
url: this.url,
words,
hashtags: []
words
};
info.hash = fnSha256Object(info);

View File

@ -124,7 +124,7 @@ export const AccountDetailsComponent: FunctionComponent<Props> = (props) => {
</div>
</div>
<div style={{ position: 'absolute', bottom: 32, width: 300 }}>
<div style={{ position: 'absolute', bottom: 0, width: 300 }}>
<div style={{ margin: 10 }}>
<Typography style={{ fontSize: '8pt', color: COLOR_DEFAULT_RED }}>
{responseError?.code} {responseError?.message}

View File

@ -26,7 +26,7 @@ interface Props {
export const MainFooterButton: FunctionComponent<Props> = (props) => {
return (
<div style={{ position: 'absolute', bottom: 32, width: 300, paddingTop: 5, backgroundColor: '#ffffff' }}>
<div style={{ position: 'absolute', bottom: 0, width: 300, paddingTop: 5, backgroundColor: '#ffffff' }}>
<div
style={{
display: props.openBugReport ? 'flex' : 'none',

View File

@ -79,8 +79,7 @@ export const NoteAddComponent: FunctionComponent<Props> = (props) => {
const data: ObjNoteDataDto = {
title,
description,
words: Array.from(words),
hashtags: []
words: Array.from(words)
};
const hash = fnSha256Object({ ...data, url, dt });
await new PageNoteAddCommand(

View File

@ -19,9 +19,9 @@ import { ICommand } from '../../common/model/shared/common.dto';
import { ObjDto, ObjTypeDto } from '../../common/model/obj/obj.dto';
import { ObjectStoreKeys } from '../../common/keys/object.store.keys';
import { ObjPageDto } from '../../common/model/obj/obj-page.dto';
import { ImageResizeFactory } from '../../common/factory/image-resize.factory';
import { ScreenshotFactory } from '../../common/factory/screenshot.factory';
import { fnConsoleLog } from '../../common/fn/fn-console';
import { ObjPageNoteDto } from '../../common/model/obj/obj-note.dto';
import { ObjPdfDto } from '../../common/model/obj/obj-pdf.dto';
export class OptionsConvertObjectsCommand implements ICommand<Promise<void>> {
async execute(): Promise<void> {
@ -29,6 +29,7 @@ export class OptionsConvertObjectsCommand implements ICommand<Promise<void>> {
}
private async convertSnapshots(): Promise<void> {
fnConsoleLog('OptionsConvertObjectsCommand->START');
let listId = await BrowserStorage.get<number>(ObjectStoreKeys.OBJECT_LIST_ID);
while (listId > 0) {
fnConsoleLog('listId', listId);
@ -40,24 +41,32 @@ export class OptionsConvertObjectsCommand implements ICommand<Promise<void>> {
case ObjTypeDto.PageElementSnapshot:
await this.convertSnapshot(obj as ObjDto<ObjPageDto>);
break;
case ObjTypeDto.PageNote:
await this.convertPageNote(obj as ObjDto<ObjPageNoteDto>);
break;
case ObjTypeDto.Pdf:
await this.convertPdf(obj as ObjDto<ObjPdfDto>);
break;
}
}
listId -= 1;
}
fnConsoleLog('OptionsConvertObjectsCommand->END');
}
private async convertPdf(obj: ObjDto<ObjPdfDto>) {
delete obj.data.data['hashtags'];
await BrowserStorage.set<ObjDto>(`${ObjectStoreKeys.OBJECT_ID}:${obj.id}`, obj);
}
private async convertPageNote(obj: ObjDto<ObjPageNoteDto>) {
delete obj.data.data['hashtags'];
await BrowserStorage.set<ObjDto>(`${ObjectStoreKeys.OBJECT_ID}:${obj.id}`, obj);
}
private async convertSnapshot(obj: ObjDto<ObjPageDto>) {
const screenshot = await ImageResizeFactory.resize2(
document,
ScreenshotFactory.THUMB_SETTINGS,
ScreenshotFactory.THUMB_SIZE,
obj.data.snapshot.data.screenshot
);
console.log('id', obj.id, 'before', obj.data.snapshot.data.screenshot.length, 'after', screenshot.length);
if (screenshot.length < obj.data.snapshot.data.screenshot.length) {
obj.data.snapshot.data.screenshot = screenshot;
await BrowserStorage.set<ObjDto>(`${ObjectStoreKeys.OBJECT_ID}:${obj.id}`, obj);
}
delete obj.data.snapshot.info['hashtags'];
await BrowserStorage.set<ObjDto>(`${ObjectStoreKeys.OBJECT_ID}:${obj.id}`, obj);
//
}
}

View File

@ -31,7 +31,7 @@ interface Props {
export const PageNoteElement: FunctionComponent<Props> = (props) => {
const [edit, setEdit] = useState<boolean>(false);
const [hashtags, setHashtags] = useState<string[]>(props.dto.data.data.hashtags);
const [hashtags, setHashtags] = useState<string[]>(props.dto.data.data.hashtags || []);
const ref = useRef<HTMLDivElement>(null);
@ -66,7 +66,7 @@ export const PageNoteElement: FunctionComponent<Props> = (props) => {
<BoardItemFooter
title="page note"
saveTags={handleTagSave}
tags={props.dto.data.data.hashtags}
tags={props.dto.data.data.hashtags || []}
createdAt={props.dto.createdAt}
words={props.dto.data.data.words}
url={props.dto.data.url?.href}

View File

@ -30,7 +30,7 @@ interface Props {
export const PageSnapshotElement: FunctionComponent<Props> = (props) => {
const [edit, setEdit] = useState<boolean>(false);
const [hashtags, setHashtags] = useState<string[]>(props.dto.data.snapshot.info.hashtags);
const [hashtags, setHashtags] = useState<string[]>(props.dto.data.snapshot.info.hashtags || []);
const handleEdit = () => {
setEdit(true);

View File

@ -22,6 +22,7 @@ import { ScreenshotSettingsComponent } from './screenshot/screenshot-settings.co
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import { OptionsConvertObjectsCommand } from '../../command/options-convert-objects.command';
import { environmentConfig } from '../../../common/environment';
const containerStyle: CSSProperties = {
margin: 10,
@ -52,9 +53,15 @@ export const SettingsComponent: FunctionComponent = () => {
<div style={containerStyle}>
<CryptoSettingsComponent></CryptoSettingsComponent>
</div>
<Button style={{ display: 'none' }} variant="outlined" onClick={handleConvert}>
Convert
</Button>
<div style={containerStyle}>
<Button
style={{ display: environmentConfig.isProduction ? 'none' : 'flex' }}
variant="outlined"
onClick={handleConvert}
>
Convert Objects
</Button>
</div>
</div>
</div>
);