feat: move video to snapshot

This commit is contained in:
Michal Szczepanski 2023-04-26 02:05:22 +02:00
parent ec0e4f1839
commit dec9b837af
6 changed files with 13 additions and 25 deletions

@ -32,6 +32,7 @@ export interface ObjSnapshotDto {
screenshot?: string;
contentId: number;
canvas?: ObjCanvasDto;
video?: ObjVideoDataDto[];
}
export interface ObjVideoDataDto {
@ -46,5 +47,4 @@ export interface ObjSnapshotContentDto {
htmlAttr: string;
css: CssStyleListDto;
content: ObjContentDto[];
video?: ObjVideoDataDto[];
}

@ -14,19 +14,20 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ObjSnapshotContentDto, ObjVideoDataDto } from '../../../common/model/obj/obj-snapshot.dto';
import { AutoTagMediator } from '../../mediator/auto-tag.mediator';
import { BrowserStorageWrapper } from '../../../common/service/browser.storage.wrapper';
import { CssFactory } from '../../factory/css.factory';
import { HtmlFactory } from '../../factory/html/html.factory';
import { ICommand } from '../../../common/model/shared/common.dto';
import { ObjNextContentIdCommand } from '../../../common/command/obj/content/obj-next-content-id.command';
import { ObjSnapshotContentDto } from '../../../common/model/obj/obj-snapshot.dto';
import { ObjectStoreKeys } from '../../../common/keys/object.store.keys';
import { fnConsoleLog } from '../../../common/fn/console.fn';
interface SnapshotResult {
id: number;
words: string[];
video: ObjVideoDataDto[];
}
export class SnapshotContentSaveCommand implements ICommand<Promise<SnapshotResult>> {
@ -59,10 +60,9 @@ export class SnapshotContentSaveCommand implements ICommand<Promise<SnapshotResu
html,
htmlAttr,
css,
video: htmlContent.video,
content: htmlContent.content
});
return { id, words };
return { id, words, video: htmlContent.video };
}
}

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ObjCanvasDto, ObjSnapshotDto } from '../../../common/model/obj/obj-snapshot.dto';
import { ObjCanvasDto, ObjSnapshotDto, ObjVideoDataDto } from '../../../common/model/obj/obj-snapshot.dto';
import { ICommand } from '../../../common/model/shared/common.dto';
import { ObjUrlDto } from '../../../common/model/obj/obj.dto';
import { ScreenshotFactory } from '../../../common/factory/screenshot.factory';
@ -29,10 +29,12 @@ export class SnapshotCreateCommand implements ICommand<Promise<ObjSnapshotDto>>
const rect = this.canvas ? this.canvas.rect : XpathFactory.computeRect(this.element);
let contentId = -1;
let words: string[] = [];
let video: ObjVideoDataDto[] = [];
if (!this.canvas) {
const res = await new SnapshotContentSaveCommand(this.element).execute();
contentId = res.id;
words = res.words;
video = res.video;
} else if (this.element instanceof HTMLImageElement) {
// TODO save image
contentId = await new SnapshotSaveImageCommand(this.element).execute();
@ -44,6 +46,7 @@ export class SnapshotCreateCommand implements ICommand<Promise<ObjSnapshotDto>>
url: this.url,
words,
hashtags: [],
video,
canvas: this.canvas,
screenshot,
contentId

@ -37,7 +37,6 @@ export class SnapshotSaveImageCommand implements ICommand<Promise<number>> {
css: {
css: []
},
video: [],
content: []
});
return id;

@ -14,9 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ObjSnapshotContentDto, ObjSnapshotDto, ObjVideoDataDto } from '../../../../common/model/obj/obj-snapshot.dto';
import { BrowserStorageWrapper } from '../../../../common/service/browser.storage.wrapper';
import { ObjectStoreKeys } from '../../../../common/keys/object.store.keys';
import { ObjSnapshotDto, ObjVideoDataDto } from '../../../../common/model/obj/obj-snapshot.dto';
import { XpathFactory } from '../../../../common/factory/xpath.factory';
import { applyStylesToElement } from '../../../../common/style.utils';
import { fnVideoSecondsTime } from '../../../../common/fn/date.fn';
@ -37,23 +35,12 @@ const titleStyle = {
export class VideoTimeComponent {
private el = document.createElement('div');
private video?: ObjVideoDataDto;
private readonly video?: ObjVideoDataDto;
constructor(private snapshot: ObjSnapshotDto) {
this.fetchSnapshot();
}
private fetchSnapshot() {
const key = `${ObjectStoreKeys.CONTENT_ID}:${this.snapshot.contentId}`;
BrowserStorageWrapper.get<ObjSnapshotContentDto>(key)
.then((content) => {
if (!content.video || content.video.length === 0) return;
this.video = content.video[0];
this.renderVideo();
})
.catch(() => {
/* IGNORE */
});
if (snapshot.video) {
this.video = snapshot.video[0];
}
}
renderVideo = () => {

@ -77,7 +77,6 @@ export class EditBarParentButton implements HtmlComponent<HTMLElement> {
const key = `${ObjectStoreKeys.CONTENT_ID}:${this.parent.object.data.snapshot.contentId}`;
const snapshot = await BrowserStorageWrapper.get<ObjSnapshotContentDto>(key);
snapshot.html = html;
snapshot.video = htmlContent.video;
snapshot.content = htmlContent.content;
await BrowserStorageWrapper.set(key, snapshot);