/** @odoo-module **/ import { registry } from "@web/core/registry"; import { url } from "@web/core/utils/urls"; import { ImageField, imageCacheKey } from '@web/views/fields/image/image_field'; import { isBinarySize } from "@web/core/utils/binary"; export const fileTypeMagicWordMap = { "/": "jpg", R: "gif", i: "png", P: "svg+xml", }; const placeholder = "/web/static/img/placeholder.png"; export class CustomImageField extends ImageField { setup() { super.setup(); // this.dialog = useService("dialog"); } getUrl(previewFieldName) { console.log('8888888888886666666666666666666') if (this.state.isValid && this.props.value) { if (isBinarySize(this.props.value) || this.props.value.length < 50) { if (!this.rawCacheKey) { this.rawCacheKey = this.props.record.data.__last_update; } return url("/web/image", { model: this.props.record.resModel, id: this.props.record.resId, field: previewFieldName, unique: imageCacheKey(this.rawCacheKey), }); } else { // Use magic-word technique for detecting image type const magic = fileTypeMagicWordMap[this.props.value[0]] || "png"; return `data:image/${magic};base64,${this.props.value}`; } } return placeholder; } } registry.category("fields").add("custom_image", CustomImageField);