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->addAllowedMediaDomain('blob:');
// Image editor
$policy->addAllowedConnectDomain('data:');
// Allow nominatim for metadata
$policy->addAllowedConnectDomain('nominatim.openstreetmap.org');
$policy->addAllowedFrameDomain('www.openstreetmap.org');

View File

@ -171,32 +171,21 @@ export default class ImageEditor extends Mixins(GlobalMixin) {
* User saved the image
*
* @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({
fullName,
imageCanvas,
mimeType,
quality,
imageBase64,
}: {
fullName?: string;
imageCanvas?: HTMLCanvasElement;
mimeType?: string;
quality?: number;
imageBase64?: string;
}): Promise<void> {
if (!imageBase64) {
throw new Error("No image data");
}
const { origin, pathname } = new URL(this.src);
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 (
!this.exif &&
!confirm(this.t("memories", "No Exif data found! Continue?"))
@ -205,9 +194,7 @@ export default class ImageEditor extends Mixins(GlobalMixin) {
}
try {
const blob = await new Promise((resolve: BlobCallback) =>
imageCanvas.toBlob(resolve, mimeType, quality)
);
const blob = await fetch(imageBase64).then((res) => res.blob());
const response = await axios.put(putUrl, new File([blob], fullName));
const fileid =
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);
}
.FIE_carousel-prev-button,
.FIE_carousel-next-button {
background: none !important;
}
</style>