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

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

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

@ -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;
}

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

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

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

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

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

@ -26,7 +26,7 @@ interface Props {
export const MainFooterButton: FunctionComponent<Props> = (props) => { export const MainFooterButton: FunctionComponent<Props> = (props) => {
return ( 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 <div
style={{ style={{
display: props.openBugReport ? 'flex' : 'none', display: props.openBugReport ? 'flex' : 'none',

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

@ -19,9 +19,9 @@ import { ICommand } from '../../common/model/shared/common.dto';
import { ObjDto, ObjTypeDto } from '../../common/model/obj/obj.dto'; import { ObjDto, ObjTypeDto } from '../../common/model/obj/obj.dto';
import { ObjectStoreKeys } from '../../common/keys/object.store.keys'; import { ObjectStoreKeys } from '../../common/keys/object.store.keys';
import { ObjPageDto } from '../../common/model/obj/obj-page.dto'; 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 { 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>> { export class OptionsConvertObjectsCommand implements ICommand<Promise<void>> {
async execute(): Promise<void> { async execute(): Promise<void> {
@ -29,6 +29,7 @@ export class OptionsConvertObjectsCommand implements ICommand<Promise<void>> {
} }
private async convertSnapshots(): Promise<void> { private async convertSnapshots(): Promise<void> {
fnConsoleLog('OptionsConvertObjectsCommand->START');
let listId = await BrowserStorage.get<number>(ObjectStoreKeys.OBJECT_LIST_ID); let listId = await BrowserStorage.get<number>(ObjectStoreKeys.OBJECT_LIST_ID);
while (listId > 0) { while (listId > 0) {
fnConsoleLog('listId', listId); fnConsoleLog('listId', listId);
@ -40,24 +41,32 @@ export class OptionsConvertObjectsCommand implements ICommand<Promise<void>> {
case ObjTypeDto.PageElementSnapshot: case ObjTypeDto.PageElementSnapshot:
await this.convertSnapshot(obj as ObjDto<ObjPageDto>); await this.convertSnapshot(obj as ObjDto<ObjPageDto>);
break; 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; 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>) { private async convertSnapshot(obj: ObjDto<ObjPageDto>) {
const screenshot = await ImageResizeFactory.resize2( delete obj.data.snapshot.info['hashtags'];
document, await BrowserStorage.set<ObjDto>(`${ObjectStoreKeys.OBJECT_ID}:${obj.id}`, obj);
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);
}
// //
} }
} }

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

@ -30,7 +30,7 @@ interface Props {
export const PageSnapshotElement: FunctionComponent<Props> = (props) => { export const PageSnapshotElement: FunctionComponent<Props> = (props) => {
const [edit, setEdit] = useState<boolean>(false); 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 = () => { const handleEdit = () => {
setEdit(true); setEdit(true);

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