feat(android): Capacitor APK build + native save/share bridge
- android/ — Capacitor project (build/, local.properties ignored) - app/js/native.js — bridge สำหรับ APK: savePhoto/saveZip/shareItems ผ่าน Filesystem+Share - app/js/csv.js — นำเข้าโฟลเดอร์หลายรายการจาก CSV (site,letter,datetime,name) - app/js/orient.js — จัดการ orientation ของ preview/กล้อง - app/manual.html + APK.md — คู่มือใช้งานและวิธี build APK - app/templates/folders-template.csv — เทมเพลต CSV - package.json / package-lock.json / capacitor.config.json / scripts/build-apk.sh - ปรับ ui, camera, exif, archive, db, naming, main, sw + css/README ตามงานข้างบน
This commit is contained in:
1 parent
a0bccc2316
commit
6f146aef59
75 files changed
+4637
-151
No files matched your search
+44
-17
@@ -3,29 +3,56 @@ import { DB_NAME, DB_VERSION, STORE_FOLDERS, STORE_IMAGES } from "./config.js";
|
||||
|
||||
let db = null;
|
||||
|
||||
function ensureSchema(req) {
|
||||
const d = req.result;
|
||||
if (!d.objectStoreNames.contains(STORE_FOLDERS)) {
|
||||
d.createObjectStore(STORE_FOLDERS, { keyPath: "id" });
|
||||
}
|
||||
if (!d.objectStoreNames.contains(STORE_IMAGES)) {
|
||||
const s = d.createObjectStore(STORE_IMAGES, { keyPath: "id" });
|
||||
s.createIndex("folderId", "folderId", { unique: false });
|
||||
s.createIndex("createdAt", "createdAt", { unique: false });
|
||||
} else {
|
||||
// อัปเกรดจาก v1: เพิ่ม index createdAt ถ้ายังไม่มี
|
||||
const s = req.transaction.objectStore(STORE_IMAGES);
|
||||
if (!s.indexNames.contains("createdAt")) {
|
||||
s.createIndex("createdAt", "createdAt", { unique: false });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const hasStores = (d) =>
|
||||
d.objectStoreNames.contains(STORE_FOLDERS) && d.objectStoreNames.contains(STORE_IMAGES);
|
||||
|
||||
export function open() {
|
||||
if (db) return Promise.resolve(db);
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = indexedDB.open(DB_NAME, DB_VERSION);
|
||||
req.onupgradeneeded = () => {
|
||||
// เปิดด้วยเวอร์ชันปัจจุบันก่อน — กัน VersionError ถ้าเครื่องมี DB ใหม่กว่า
|
||||
const req = indexedDB.open(DB_NAME);
|
||||
|
||||
req.onupgradeneeded = () => ensureSchema(req);
|
||||
|
||||
req.onsuccess = () => {
|
||||
const d = req.result;
|
||||
if (!d.objectStoreNames.contains(STORE_FOLDERS)) {
|
||||
d.createObjectStore(STORE_FOLDERS, { keyPath: "id" });
|
||||
}
|
||||
if (!d.objectStoreNames.contains(STORE_IMAGES)) {
|
||||
const s = d.createObjectStore(STORE_IMAGES, { keyPath: "id" });
|
||||
s.createIndex("folderId", "folderId", { unique: false });
|
||||
s.createIndex("createdAt", "createdAt", { unique: false });
|
||||
} else {
|
||||
// อัปเกรดจาก v1: เพิ่ม index createdAt ถ้ายังไม่มี (ของเดิมเรียงตาม id ได้อยู่แล้ว)
|
||||
const s = req.transaction.objectStore(STORE_IMAGES);
|
||||
if (!s.indexNames.contains("createdAt")) {
|
||||
s.createIndex("createdAt", "createdAt", { unique: false });
|
||||
}
|
||||
if (hasStores(d)) {
|
||||
// ปิด connection เองเมื่อมีการขออัปเกรดจากแท็บอื่น กันการบล็อกค้าง
|
||||
d.onversionchange = () => { try { d.close(); } catch {} db = null; };
|
||||
db = d; resolve(db); return;
|
||||
}
|
||||
|
||||
// DB มีอยู่แต่ไม่มี store (เช่นเคยถูกสร้างว่างจากสคริปต์อื่น) → อัปเกรด schemas
|
||||
const next = d.version + 1;
|
||||
d.close();
|
||||
const up = indexedDB.open(DB_NAME, next);
|
||||
up.onupgradeneeded = () => ensureSchema(up);
|
||||
up.onsuccess = () => { db = up.result; resolve(db); };
|
||||
up.onerror = () => reject(up.error);
|
||||
};
|
||||
|
||||
req.onerror = () => {
|
||||
// ถ้าเปิดไม่ได้เพราะเวอร์ชันต่ำกว่า ให้ลองแบบไม่ระบุเวอร์ชันซ้ำ
|
||||
reject(req.error);
|
||||
};
|
||||
req.onsuccess = () => { db = req.result; resolve(db); };
|
||||
req.onerror = () => reject(req.error);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user