Files
monkey-ai-web/src/pages/WebsiteSettings/qrPreview.js
T

41 lines
1.4 KiB
JavaScript

/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
// Local preview is disabled; uploads use the backend resource endpoint.
export const LOCAL_QR_PREVIEW_ENABLED = false;
export function isLocalQrPreview(value) {
return (
LOCAL_QR_PREVIEW_ENABLED &&
/^data:image\/(?:jpeg|png|webp);base64,(?:[A-Za-z0-9+/]{4})+(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(
value,
)
);
}
export function readLocalQrPreview(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = () => reject(new Error('图片读取失败,请重新选择'));
reader.onabort = () => reject(new Error('图片读取已取消,请重新选择'));
reader.readAsDataURL(file);
});
}