editor: use b64 for save

pull/221/head
Varun Patil 2022-11-09 21:55:14 -08:00
parent 0dc4784f1a
commit 5519020c2a
2 changed files with 15 additions and 20 deletions

View File

@ -103,6 +103,9 @@ class PageController extends Controller
$policy->addAllowedScriptDomain('blob:'); $policy->addAllowedScriptDomain('blob:');
$policy->addAllowedMediaDomain('blob:'); $policy->addAllowedMediaDomain('blob:');
// Image editor
$policy->addAllowedConnectDomain('data:');
// Allow nominatim for metadata // Allow nominatim for metadata
$policy->addAllowedConnectDomain('nominatim.openstreetmap.org'); $policy->addAllowedConnectDomain('nominatim.openstreetmap.org');
$policy->addAllowedFrameDomain('www.openstreetmap.org'); $policy->addAllowedFrameDomain('www.openstreetmap.org');

View File

@ -171,32 +171,21 @@ export default class ImageEditor extends Mixins(GlobalMixin) {
* User saved the image * User saved the image
* *
* @see https://github.com/scaleflex/filerobot-image-editor#onsave * @see https://github.com/scaleflex/filerobot-image-editor#onsave
* @param {object} props destructuring object
* @param {string} props.fullName the file name
* @param {HTMLCanvasElement} props.imageCanvas the image canvas
* @param {string} props.mimeType the image mime type
* @param {number} props.quality the image saving quality
*/ */
async onSave({ async onSave({
fullName, fullName,
imageCanvas, imageBase64,
mimeType,
quality,
}: { }: {
fullName?: string; fullName?: string;
imageCanvas?: HTMLCanvasElement; imageBase64?: string;
mimeType?: string;
quality?: number;
}): Promise<void> { }): Promise<void> {
if (!imageBase64) {
throw new Error("No image data");
}
const { origin, pathname } = new URL(this.src); const { origin, pathname } = new URL(this.src);
const putUrl = origin + join(dirname(pathname), fullName); const putUrl = origin + join(dirname(pathname), fullName);
// toBlob is not very smart...
mimeType = mimeType.replace("jpg", "jpeg");
// Sanity check, 0 < quality < 1
quality = Math.max(Math.min(quality, 1), 0) || 1;
if ( if (
!this.exif && !this.exif &&
!confirm(this.t("memories", "No Exif data found! Continue?")) !confirm(this.t("memories", "No Exif data found! Continue?"))
@ -205,9 +194,7 @@ export default class ImageEditor extends Mixins(GlobalMixin) {
} }
try { try {
const blob = await new Promise((resolve: BlobCallback) => const blob = await fetch(imageBase64).then((res) => res.blob());
imageCanvas.toBlob(resolve, mimeType, quality)
);
const response = await axios.put(putUrl, new File([blob], fullName)); const response = await axios.put(putUrl, new File([blob], fullName));
const fileid = const fileid =
parseInt(response?.headers?.["oc-fileid"]?.split("oc")[0]) || null; parseInt(response?.headers?.["oc-fileid"]?.split("oc")[0]) || null;
@ -645,4 +632,9 @@ export default class ImageEditor extends Mixins(GlobalMixin) {
filter: var(--background-invert-if-dark); filter: var(--background-invert-if-dark);
} }
.FIE_carousel-prev-button,
.FIE_carousel-next-button {
background: none !important;
}
</style> </style>