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 ตามงานข้างบน
No files matched your search
@@ -0,0 +1,116 @@
|
||||
# ทำ CamCat เป็นไฟล์ .apk
|
||||
|
||||
## ตอบสั้น ๆ
|
||||
|
||||
ทำได้ — แต่ "เว็บแอป" คอมไพล์เป็น APK ตรง ๆ ไม่ได้ ต้องห่อด้วย **Capacitor (WebView + native bridge)**
|
||||
ซึ่งจะได้ APK จริงที่เข้าถึง **กล้อง**, **ไฟล์ในเครื่อง** และ **share sheet ของ Android** ได้เต็มกว่าเดิม
|
||||
|
||||
| ทาง | ได้อะไร | ข้อจำกัด |
|
||||
|---|---|---|
|
||||
| PWA (ตอนนี้) | ติดตั้งจาก Chrome, กล้อง, ZIP ดาวน์โหลด | ไฟล์ลง Download, แชร์ไฟล์ได้จำกัด, ไม่มีไอคอนแอปจริง |
|
||||
| TWA (Bubblewrap/PWABuilder) | APK จาก Play Store ได้ | ยังเป็นเว็บล้วน — เข้าถึงไฟล์/แชร์ได้เท่าเดิม |
|
||||
| **Capacitor WebView** (แนะนำ) | APK + ปลั๊กอิน Filesystem/Share/Camera | ต้อง build ด้วย Android SDK, APK ใหญ่ขึ้น ~4–6 MB |
|
||||
|
||||
## สิ่งที่ปรับในโค้ดแล้ว
|
||||
|
||||
- `app/js/native.js` — bridge ตรวจว่ากำลังรันใน APK (`Capacitor.isNativePlatform()`)
|
||||
- `savePhoto()` → เขียนรูปจริงที่ `Documents/CamCat/<ชื่อโฟลเดอร์>/<ไฟล์>.jpg`
|
||||
- `saveZip()` → เขียน ZIP ที่ `Documents/CamCat-ZIP/`
|
||||
- `shareItems()` → เปิด share sheet ของ Android ด้วย FileProvider (รูปเดี่ยว/หลายรูป/ZIP)
|
||||
- บนเว็บทุกฟังก์ชันคืน `null` → ใช้ทางเดิม (ดาวน์โหลด/Web Share) ไม่กระทบ PWA
|
||||
- ถ่ายรูปใน APK = บันทึกทั้งใน IndexedDB **และ** ลงโฟลเดอร์จริงในเครื่องทันที
|
||||
- ปุ่ม ZIP (โฟลเดอร์เดียว / ทุกโฟลเดอร์) ใน APK = เขียนลง `Documents/CamCat-ZIP` แทนการดาวน์โหลด
|
||||
- หน้า diagnostics เพิ่มบรรทัด “โหมดแอป” และ “ที่เก็บไฟล์”
|
||||
|
||||
## build
|
||||
|
||||
ต้องมี **JDK 17** และ **Android SDK** (ยังไม่มีในเครื่องนี้)
|
||||
|
||||
```bash
|
||||
# 1) JDK 17 (Temurin) → ตั้ง JAVA_HOME
|
||||
# 2) Android SDK commandline-tools → ตั้ง ANDROID_HOME + sdkmanager --licenses
|
||||
# ติดตั้ง: platform-tools, platforms;android-34, build-tools;34.0.0
|
||||
|
||||
cd <repo>
|
||||
./scripts/build-apk.sh # npm install → cap add android → cap sync → assembleDebug
|
||||
# APK: android/app/build/outputs/apk/debug/app-debug.apk
|
||||
```
|
||||
|
||||
ติดตั้งลงเครื่อง: เปิด “ติดตั้งจากแหล่งที่ไม่รู้จัก” แล้วกดไฟล์ APK (หรือ `adb install -r app-debug.apk`)
|
||||
|
||||
## สิทธิ์ใน AndroidManifest (Capacitor สร้างให้บางส่วน — เติมเอง)
|
||||
|
||||
```xml
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
```
|
||||
|
||||
## กล้องใน WebView
|
||||
|
||||
`getUserMedia()` ใน WebView ต้องมีสิทธิ์ CAMERA และ WebChromeClient อนุญาตคำขอ
|
||||
ถ้าเปิดแอปแล้วภาพกล้องไม่ขึ้น ให้เพิ่มใน `MainActivity` (fallback):
|
||||
|
||||
```java
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] results) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, results);
|
||||
// Capacitor จะส่งต่อผลให้ WebView เองในเวอร์ชันใหม่
|
||||
}
|
||||
```
|
||||
|
||||
ถ้ายังไม่ขึ้น ทางเลือกที่เสถียรกว่า: ใช้ `@capacitor/camera` ถ่ายภาพนิ่ง (ได้ JPEG + EXIF เต็ม)
|
||||
แล้วคงพรีวิวด้วย `getUserMedia` — โค้ดฝั่งเว็บแยกอยู่แล้วที่ `js/camera.js`
|
||||
|
||||
## แชร์ “โฟลเดอร์”
|
||||
|
||||
Android แชร์ URI ของ **โฟลเดอร์** ผ่าน share sheet ไม่ได้ (intent รับได้เฉพาะไฟล์)
|
||||
จึงมี 2 ทางที่ทำได้จริง:
|
||||
|
||||
1. **แชร์ ZIP** — โฟลเดอร์อยู่ข้างใน zip (โครงสร้าง `<ชื่อโฟลเดอร์>/<รูป>.jpg`)
|
||||
2. **แชร์หลายรูปพร้อมกัน** — `shareItems([{name, blob}, …])` ส่งหลาย URI ในครั้งเดียว
|
||||
|
||||
## เซ็น release (ภายหลัง)
|
||||
|
||||
```bash
|
||||
keytool -genkey -v -keystore camcat.jks -keyalg RSA -keysize 2048 -validity 10000 -alias camcat
|
||||
# android/key.properties + build.gradle signingConfigs → assembleRelease
|
||||
```
|
||||
|
||||
|
||||
## APK ที่ build แล้ว (เครื่องนี้)
|
||||
|
||||
| รายการ | ค่า |
|
||||
|---|---|
|
||||
| ไฟล์ | `dist/CamCat-1.0-debug.apk` (3.8 MB) |
|
||||
| Package | `com.camcat.app` · label `CamCat` |
|
||||
| Permissions | CAMERA, ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION, WRITE_EXTERNAL_STORAGE (≤API 29) |
|
||||
| Build | Gradle 8.2.1 + AGP + SDK 34, debug keystore |
|
||||
| Toolchain ที่ติดตั้ง | `D:\AndroidToolchain\jdk-17.0.13`, `D:\AndroidToolchain\Sdk` |
|
||||
|
||||
ติดตั้ง: คัดลอก APK ไปมือถือ → เปิด “ติดตั้งจากแหล่งที่ไม่รู้จัก” → กดติดตั้ง
|
||||
หรือ `adb install -r dist/CamCat-1.0-debug.apk`
|
||||
|
||||
### ที่เก็บไฟล์ใน APK
|
||||
|
||||
`native.js` จะลองเขียน `DOCUMENTS` ก่อน (Android ≤10 เห็นใน My Files/Pictures)
|
||||
ถ้าระบบปฏิเสธ (Android 11+ scoped storage) จะ fallback ไป app-specific external
|
||||
(`Android/data/com.camcat.app/files/CamCat/...`) — ยังเข้าถึงได้ทาง USB/File Manager
|
||||
ถ้าต้องการให้ลง `Documents`/`DCIM` จริงบน Android 11+ ต้องเพิ่มปลั๊กอิน MediaStore
|
||||
(`@capacitor-community/media`) หรือขอ MANAGE_EXTERNAL_STORAGE (ข้อจำกัดของ Play Store)
|
||||
|
||||
|
||||
## v1.1 (ล่าสุด)
|
||||
|
||||
- ล็อกแนวตั้ง `android:screenOrientation="portrait"` — ถือแนวนอน UI ไม่หมุน
|
||||
- เลือกอัตราส่วนภาพ 4:3 / 3:4 ได้ (กรอบพรีวิว + ครอปไฟล์จริง + เก็บใน meta.ratio)
|
||||
- กันกล้องค้าง: `takePhoto()` timeout 4s, capture timeout 12s, watchdog 20s
|
||||
- APK: `dist/CamCat-1.1-debug.apk`
|
||||
|
||||
|
||||
## v1.2
|
||||
|
||||
- Auto-orient: อ่าน EXIF Orientation → bake พิกเซลให้ตรง → เขียน Orientation = 1 (กันแอปอื่นหมุนซ้ำ)
|
||||
- ปุ่มหมุนซ้าย/ขวา 90° ในชีตรูป (บันทึกลง DB + เขียน EXIF ใหม่)
|
||||
- ปุ่ม Volume up/down เป็นชัตเตอร์ (MainActivity → CustomEvent `camcat:shutter`, debounce 0.6s)
|
||||
- APK: `dist/CamCat-1.2-debug.apk`
|
||||
@@ -0,0 +1,101 @@
|
||||
# Using Android gitignore template: https://github.com/github/gitignore/blob/HEAD/Android.gitignore
|
||||
|
||||
# Built application files
|
||||
*.apk
|
||||
*.aar
|
||||
*.ap_
|
||||
*.aab
|
||||
|
||||
# Files for the ART/Dalvik VM
|
||||
*.dex
|
||||
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
out/
|
||||
# Uncomment the following line in case you need and you don't have the release build type files in your app
|
||||
# release/
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
# Log Files
|
||||
*.log
|
||||
|
||||
# Android Studio Navigation editor temp files
|
||||
.navigation/
|
||||
|
||||
# Android Studio captures folder
|
||||
captures/
|
||||
|
||||
# IntelliJ
|
||||
*.iml
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.idea/gradle.xml
|
||||
.idea/assetWizardSettings.xml
|
||||
.idea/dictionaries
|
||||
.idea/libraries
|
||||
# Android Studio 3 in .gitignore file.
|
||||
.idea/caches
|
||||
.idea/modules.xml
|
||||
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
|
||||
.idea/navEditor.xml
|
||||
|
||||
# Keystore files
|
||||
# Uncomment the following lines if you do not want to check your keystore files in.
|
||||
#*.jks
|
||||
#*.keystore
|
||||
|
||||
# External native build folder generated in Android Studio 2.2 and later
|
||||
.externalNativeBuild
|
||||
.cxx/
|
||||
|
||||
# Google Services (e.g. APIs or Firebase)
|
||||
# google-services.json
|
||||
|
||||
# Freeline
|
||||
freeline.py
|
||||
freeline/
|
||||
freeline_project_description.json
|
||||
|
||||
# fastlane
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots
|
||||
fastlane/test_output
|
||||
fastlane/readme.md
|
||||
|
||||
# Version control
|
||||
vcs.xml
|
||||
|
||||
# lint
|
||||
lint/intermediates/
|
||||
lint/generated/
|
||||
lint/outputs/
|
||||
lint/tmp/
|
||||
# lint/reports/
|
||||
|
||||
# Android Profiling
|
||||
*.hprof
|
||||
|
||||
# Cordova plugins for Capacitor
|
||||
capacitor-cordova-android-plugins
|
||||
|
||||
# Copied web assets
|
||||
app/src/main/assets/public
|
||||
|
||||
# Generated Config files
|
||||
app/src/main/assets/capacitor.config.json
|
||||
app/src/main/assets/capacitor.plugins.json
|
||||
app/src/main/res/xml/config.xml
|
||||
@@ -0,0 +1,2 @@
|
||||
/build/*
|
||||
!/build/.npmkeep
|
||||
@@ -0,0 +1,54 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
namespace "com.camcat.app"
|
||||
compileSdk rootProject.ext.compileSdkVersion
|
||||
defaultConfig {
|
||||
applicationId "com.camcat.app"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
aaptOptions {
|
||||
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
||||
// Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
|
||||
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
flatDir{
|
||||
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
||||
implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
|
||||
implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
|
||||
implementation project(':capacitor-android')
|
||||
testImplementation "junit:junit:$junitVersion"
|
||||
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
||||
implementation project(':capacitor-cordova-android-plugins')
|
||||
}
|
||||
|
||||
apply from: 'capacitor.build.gradle'
|
||||
|
||||
try {
|
||||
def servicesJSON = file('google-services.json')
|
||||
if (servicesJSON.text) {
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
}
|
||||
} catch(Exception e) {
|
||||
logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
|
||||
|
||||
android {
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
|
||||
dependencies {
|
||||
implementation project(':capacitor-filesystem')
|
||||
implementation project(':capacitor-share')
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (hasProperty('postBuildExtras')) {
|
||||
postBuildExtras()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.getcapacitor.myapp;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
|
||||
@Test
|
||||
public void useAppContext() throws Exception {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
|
||||
assertEquals("com.getcapacitor.app", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- กล้องสำหรับ getUserMedia / ImageCapture ใน WebView -->
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<!-- พิกัดสำหรับ EXIF GPS -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<!-- เขียนไฟล์บน Android 10 ลงไป (Documents) -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="29" />
|
||||
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/title_activity_main"
|
||||
android:theme="@style/AppTheme.NoActionBarLaunch"
|
||||
android:launchMode="singleTask"
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths"></meta-data>
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
<!-- Permissions -->
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.camcat.app;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.getcapacitor.BridgeActivity;
|
||||
|
||||
/**
|
||||
* CamCat — ใช้ปุ่มเพิ่ม/ลดเสียงเป็นชัตเตอร์ (เฉพาะ APK)
|
||||
* ปุ่มเสียงถูกระบบกลืนก่อนถึง WebView จึงต้องดักที่ Activity แล้วส่ง event เข้า JS
|
||||
*/
|
||||
public class MainActivity extends BridgeActivity {
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
int code = event.getKeyCode();
|
||||
if (code == KeyEvent.KEYCODE_VOLUME_UP || code == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
|
||||
triggerShutter(code == KeyEvent.KEYCODE_VOLUME_UP ? "up" : "down");
|
||||
}
|
||||
return true; // ไม่ให้ event ไปเปลี่ยนระดับเสียง
|
||||
}
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
private void triggerShutter(final String key) {
|
||||
if (getBridge() == null || getBridge().getWebView() == null) return;
|
||||
getBridge().getWebView().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String js = "window.dispatchEvent(new CustomEvent('camcat:shutter',{detail:{key:'"
|
||||
+ key + "'}}));";
|
||||
getBridge().getWebView().evaluateJavascript(js, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 17 KiB |
@@ -0,0 +1,34 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="78.5885"
|
||||
android:endY="90.9159"
|
||||
android:startX="48.7653"
|
||||
android:startY="61.0927"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1" />
|
||||
</vector>
|
||||
@@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillColor="#26A69A"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
</vector>
|
||||
|
After Width: | Height: | Size: 3.9 KiB |
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<WebView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
||||
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#FFFFFF</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<resources>
|
||||
<string name="app_name">CamCat</string>
|
||||
<string name="title_activity_main">CamCat</string>
|
||||
<string name="package_name">com.camcat.app</string>
|
||||
<string name="custom_url_scheme">com.camcat.app</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:background">@null</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
|
||||
<item name="android:background">@drawable/splash</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-path name="my_images" path="." />
|
||||
<cache-path name="my_cache_images" path="." />
|
||||
</paths>
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.getcapacitor.myapp;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
|
||||
@Test
|
||||
public void addition_isCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.2.1'
|
||||
classpath 'com.google.gms:google-services:4.4.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "variables.gradle"
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
|
||||
include ':capacitor-android'
|
||||
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')
|
||||
|
||||
include ':capacitor-filesystem'
|
||||
project(':capacitor-filesystem').projectDir = new File('../node_modules/@capacitor/filesystem/android')
|
||||
|
||||
include ':capacitor-share'
|
||||
project(':capacitor-share').projectDir = new File('../node_modules/@capacitor/share/android')
|
||||
@@ -0,0 +1,22 @@
|
||||
# Project-wide Gradle settings.
|
||||
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app's APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
@@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,248 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
@@ -0,0 +1,92 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,5 @@
|
||||
include ':app'
|
||||
include ':capacitor-cordova-android-plugins'
|
||||
project(':capacitor-cordova-android-plugins').projectDir = new File('./capacitor-cordova-android-plugins/')
|
||||
|
||||
apply from: 'capacitor.settings.gradle'
|
||||
@@ -0,0 +1,16 @@
|
||||
ext {
|
||||
minSdkVersion = 22
|
||||
compileSdkVersion = 34
|
||||
targetSdkVersion = 34
|
||||
androidxActivityVersion = '1.8.0'
|
||||
androidxAppCompatVersion = '1.6.1'
|
||||
androidxCoordinatorLayoutVersion = '1.2.0'
|
||||
androidxCoreVersion = '1.12.0'
|
||||
androidxFragmentVersion = '1.6.2'
|
||||
coreSplashScreenVersion = '1.0.1'
|
||||
androidxWebkitVersion = '1.9.0'
|
||||
junitVersion = '4.13.2'
|
||||
androidxJunitVersion = '1.1.5'
|
||||
androidxEspressoCoreVersion = '3.5.1'
|
||||
cordovaAndroidVersion = '10.1.1'
|
||||
}
|
||||
@@ -5,15 +5,23 @@ PWA ถ่ายรูปหน้างาน แยกโฟลเดอร์
|
||||
|
||||
## Features
|
||||
|
||||
- กล้องหลัง/หน้า, ไฟแฟลช (torch), ซูมแบบ pills 1×/2×/3×, เส้นแบ่ง 3 ส่วน
|
||||
- กล้องหลัง/หน้า, ไฟแฟลช (torch), ซูมแบบ pills 1×/2×/3×, เส้นแบ่ง 3 ส่วน, อัตราส่วนภาพ 4:3 / 3:4 (ครอปจริง)
|
||||
- จัดทิศทางภาพอัตโนมัติ (EXIF Orientation → หมุนพิกเซล → Orientation=1) + ปุ่มหมุนซ้าย/ขวาในชีตรูป
|
||||
- APK: ปุ่มเพิ่ม/ลดเสียง = ชัตเตอร์, ล็อกแนวตั้ง
|
||||
- ถ่ายด้วย `ImageCapture.takePhoto()` (ความละเอียดเต็ม) fallback เป็น canvas
|
||||
- เขียน EXIF ลงไฟล์จริง (Make/Model/DateTimeOriginal/GPS) ก่อนบันทึก → ติดไปตอนแชร์
|
||||
- โฟลเดอร์ชื่อเริ่มต้น `Site A <ปี พ.ศ.>-<เดือน>-<วัน>` อัตโนมัติ (Asia/Bangkok)
|
||||
- ZIP **ทุกรูปในโฟลเดอร์** + `metadata.json` แล้วดาวน์โหลดลงเครื่อง
|
||||
- ปุ่มแชร์ = สร้าง ZIP แล้วส่งเข้า share sheet ของ Samsung ไปแอปอื่น (fallback = ดาวน์โหลด)
|
||||
- เขียน EXIF มาตรฐานลงไฟล์จริงก่อนบันทึก (Make/Model/Software/DateTimeOriginal/ExifVersion/ColorSpace/Resolution/ImageUniqueID + GPS ละเอียด/เวลา/ความแม่นยำ) → ติดไปตอนแชร์
|
||||
- โฟลเดอร์ชื่อเริ่มต้นอัตโนมัติ: `Site <ตัวอักษร> <ปี พ.ศ.>.<เดือน>.<วัน>.<ชั่วโมง>.<นาที>`
|
||||
- ตัวอักษรไล่ a…z แล้วต่อ aa, ab … az, ba … (แบบคอลัมน์ Excel)
|
||||
- ปุ่ม `+` บนหัวแอป = สร้างทันที · ปุ่ม "โฟลเดอร์ใหม่" = เปิดชีตแก้ชื่อก่อนสร้าง · เปลี่ยนชื่อทีหลังได้ (ปุ่มดินสอ)
|
||||
- นำเข้าโฟลเดอร์ทีละหลายรายการจาก CSV (ดูหัวตารางด้านล่าง) — ไฟล์เปล่า: `templates/folders-template.csv`
|
||||
- ZIP **ทุกรูปในโฟลเดอร์** (มีแต่ JPEG — metadata อยู่ใน EXIF ของแต่ละไฟล์) แล้วดาวน์โหลดลงเครื่อง
|
||||
- โครงสร้างใน zip = `<ชื่อโฟลเดอร์>/<ไฟล์>.jpg` → แตกออกมาเป็นโฟลเดอร์จริง
|
||||
- ปุ่ม **ZIP ทุกโฟลเดอร์** ที่หน้าโฟลเดอร์ → ไฟล์เดียว `CamCat-all-<stamp>.zip` แยกโฟลเดอร์ย่อยครบทุกโฟลเดอร์
|
||||
- ปุ่ม ZIP = รวมทุกรูปในโฟลเดอร์แล้วดาวน์โหลดลงเครื่อง (ปุ่มแชร์ ZIP ถูกถอดออกตามคำสั่ง)
|
||||
- ธีมสว่าง/มืด/ตามระบบ (จำค่าไว้), safe-area, 100dvh, ปุ่ม ≥44px ตาม One UI
|
||||
- QR ลิงก์ทดสอบบนมือถือ (ต้อง HTTPS) + หน้าข้อมูลอุปกรณ์/กล้อง (diagnostics)
|
||||
- Offline: Service Worker + IndexedDB, ติดตั้งเป็น PWA ได้
|
||||
- คู่มือใช้งานหน้าเดียว (standalone HTML, พิมพ์/บันทึก PDF ได้): `manual.html` → เปิดที่ `/manual.html`
|
||||
|
||||
## Design (One UI)
|
||||
|
||||
@@ -27,6 +35,44 @@ PWA ถ่ายรูปหน้างาน แยกโฟลเดอร์
|
||||
| Accessibility | ข้อความ ≥4.5:1, ปุ่ม ≥44px, reduced-motion, focus ring |
|
||||
| หน้าเมนูกล้อง | โครมดำทั้งหน้าแบบ One UI Camera |
|
||||
|
||||
## นำเข้าโฟลเดอร์จาก CSV
|
||||
|
||||
หัวตาราง 4 คอลัมน์ (ทุกคอลัมน์เว้นว่างได้):
|
||||
|
||||
| คอลัมน์ | ความหมาย |
|
||||
|---|---|
|
||||
| `site` | คำนำหน้า เช่น `Site` (เว้นว่าง = `Site`) |
|
||||
| `letter` | `a`…`z`, `aa`… (เว้นว่าง = ไล่ต่อจากโฟลเดอร์ที่มีอยู่ให้อัตโนมัติ) |
|
||||
| `datetime` | `2569.10.25.21.45` (รับ `-` `/` `:` หรือ ค.ศ. ได้ เช่น `2026-10-25 21:45`) |
|
||||
| `name` | ชื่อเต็ม ถ้าใส่จะใช้ค่านี้แทนการประกอบชื่อ |
|
||||
|
||||
ตัวอย่าง:
|
||||
|
||||
```csv
|
||||
site,letter,datetime,name
|
||||
Site,a,2569.10.25.21.45,
|
||||
Site,b,2569.10.25.22.10,
|
||||
Site,,2569.10.26.08.00,หน้างานพิเศษ
|
||||
```
|
||||
|
||||
กติกาที่ระบบบังคับ: `letter` ต้อง a-z · `datetime` ต้องอ่านเป็นวันเวลาได้ · ชื่อซ้ำจะถูกข้ามพร้อมรายงานแถวที่ผิด
|
||||
|
||||
## ปุ่มแชร์ ZIP (Web Share)
|
||||
|
||||
1. ZIP ถูกสร้างล่วงหน้าหลังเปิดแกลเลอรี → กด "แชร์ ZIP" แล้วเรียก `navigator.share({files})` ทันทีในจังหวะแตะ (ไม่ให้ user activation หมดอายุ)
|
||||
2. ถ้ายังไม่มี ZIP / เบราว์เซอร์ตัดสิทธิ์ → เปิดชีต "ZIP พร้อมแล้ว" ให้กด "แชร์ไปแอปอื่น" อีกครั้ง (activation ใหม่) หรือ "บันทึกไฟล์"
|
||||
3. เบราว์เซอร์ที่ไม่รองรับแชร์ไฟล์ (เช่น Samsung Internet บางเวอร์ชัน) → ปุ่มแชร์ถูกปิด พร้อมปุ่มบันทึกไฟล์แทน
|
||||
|
||||
## EXIF ที่ฝังในไฟล์ (per photo)
|
||||
|
||||
| IFD | tag |
|
||||
|---|---|
|
||||
| IFD0 | 270 ImageDescription (`CamCat · <โฟลเดอร์>`) · 271 Make `samsung` · 272 Model `SM-S911B` · 274 Orientation · 282/283/296 Resolution · 305 Software · 306 DateTime |
|
||||
| Exif | 36864 ExifVersion 0232 · 36867/36868 DateTimeOriginal/Digitized · 37121 ComponentsConfiguration · 37380 ExposureBias · 40961 ColorSpace sRGB · 40962/40963 Pixel dims · 41985–41994 (rendering modes) · 42016 ImageUniqueID |
|
||||
| GPS | 0 Version · 1/2 LatRef+Lat · 3/4 LonRef+Lon · 5/6 Altitude · 7 TimeStamp · 27 ProcessingMethod · 29 DateStamp · 31 HPositioningError (±เมตร) |
|
||||
|
||||
ไม่มีไฟล์ JSON แยก — เปิดรูปด้วยแอป Samsung Gallery / Google Photos / exiftool แล้วเห็นค่าพวกนี้ทันที
|
||||
|
||||
## รันทดสอบ
|
||||
|
||||
```bash
|
||||
|
||||
@@ -185,6 +185,11 @@ header h1 {
|
||||
}
|
||||
.icon-round svg { width: 22px; height: 22px; }
|
||||
.icon-round:active { transform: scale(0.94); background: var(--bg-2); }
|
||||
.icon-round.primary { background: var(--accent); color: var(--on-accent); }
|
||||
.icon-round.primary:active { background: var(--accent); filter: brightness(0.94); }
|
||||
|
||||
.head-btns { display: flex; gap: 8px; align-items: center; }
|
||||
.head-btns .btn { min-height: 40px; padding: 0 14px; font-size: 13px; }
|
||||
|
||||
/* ── Main ────────────────────────────────────────────────── */
|
||||
main {
|
||||
@@ -267,6 +272,27 @@ nav button:active .tab-ico { background: var(--bg-2); }
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* กรอบพรีวิวตามอัตราส่วนที่เลือก — เห็นอะไร ได้อย่างนั้น */
|
||||
.frame {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
}
|
||||
/* ขนาดกรอบคำนวณด้วย JS (fitFrame) เพื่อไม่ให้ aspect-ratio ถูก max-height บิด */
|
||||
.frame.ratio-43, .frame.ratio-34 { width: 100%; height: 100%; }
|
||||
|
||||
.cam-chip.ratio-chip {
|
||||
width: auto;
|
||||
min-width: 52px;
|
||||
padding: 0 14px;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
#video {
|
||||
@@ -276,6 +302,8 @@ nav button:active .tab-ico { background: var(--bg-2); }
|
||||
display: block;
|
||||
background: #000;
|
||||
}
|
||||
.frame > #video, .frame > .grid-lines { position: absolute; inset: 0; }
|
||||
.grid-lines { position: absolute; }
|
||||
|
||||
.grid-lines {
|
||||
position: absolute;
|
||||
@@ -521,6 +549,9 @@ nav button:active .tab-ico { background: var(--bg-2); }
|
||||
.icon-btn:active { background: var(--bg-2); }
|
||||
.icon-btn.danger { color: var(--danger); }
|
||||
|
||||
.folder-bulk { padding: 4px var(--pad) 12px; }
|
||||
.folder-bulk .btn { min-height: 50px; }
|
||||
|
||||
.storage-line {
|
||||
padding: 4px var(--pad) calc(20px + 4px);
|
||||
font-size: 12.5px;
|
||||
@@ -530,11 +561,14 @@ nav button:active .tab-ico { background: var(--bg-2); }
|
||||
}
|
||||
|
||||
/* ── Gallery ─────────────────────────────────────────────── */
|
||||
.folder-view,
|
||||
.gallery-view {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100%;
|
||||
}
|
||||
.folder-view .folder-list { flex: 1; }
|
||||
.folder-view .storage-line { padding-bottom: 6px; }
|
||||
.gallery-view .gallery-grid { flex: 1; align-content: start; }
|
||||
|
||||
.gallery-grid {
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
</button>
|
||||
</div>
|
||||
<div class="head-actions">
|
||||
<button class="icon-round primary" type="button" data-action="quick-new-folder" aria-label="สร้างโฟลเดอร์ใหม่ทันที">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg>
|
||||
</button>
|
||||
<button class="icon-round" id="theme-toggle" type="button" aria-label="สลับธีมสว่าง/มืด"></button>
|
||||
<button class="icon-round" type="button" data-action="diagnostics" aria-label="ข้อมูลอุปกรณ์และกล้อง">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/></svg>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// ── ZIP ทั้งโฟลเดอร์: สร้าง / ดาวน์โหลด / แชร์ผ่านระบบมือถือ ──
|
||||
import { safeFileName, humanDateTime } from "./naming.js";
|
||||
// ── ZIP: สร้าง / ดาวน์โหลด (ทุกโฟลเดอร์ หรือโฟลเดอร์เดียว) ──
|
||||
// โครงสร้างใน ZIP: <ชื่อโฟลเดอร์>/<ชื่อไฟล์>.jpg → แตกไฟล์ออกมาเป็นโฟลเดอร์จริง
|
||||
import { safeFileName, fileStamp } from "./naming.js";
|
||||
|
||||
const cache = { signature: "", file: null, fileName: "" };
|
||||
|
||||
@@ -11,49 +12,87 @@ function entryBase(folder) {
|
||||
return safeFileName(folder.name).replace(/\s+/g, "_");
|
||||
}
|
||||
|
||||
/** ชื่อโฟลเดอร์ภายใน zip — กันซ้ำและตัดอักขระที่ทำให้ path เพี้ยน */
|
||||
function folderDirName(folder, used) {
|
||||
const base = safeFileName(folder.name, "photos").replace(/[\\/]+/g, "-").replace(/\.+$/, "").trim() || "photos";
|
||||
let dir = base;
|
||||
let n = 2;
|
||||
while (used.has(dir.toLowerCase())) dir = `${base} (${n++})`;
|
||||
used.add(dir.toLowerCase());
|
||||
return dir;
|
||||
}
|
||||
|
||||
/** กันชื่อไฟล์ซ้ำภายในโฟลเดอร์เดียว (เช่นหลังเปลี่ยนชื่อโฟลเดอร์) */
|
||||
function uniqueEntryName(name, usedNames) {
|
||||
const clean = String(name || "photo.jpg").replace(/[\\/]+/g, "-");
|
||||
let cand = clean;
|
||||
let n = 2;
|
||||
while (usedNames.has(cand.toLowerCase())) {
|
||||
cand = clean.replace(/(\.[a-z0-9]+)?$/i, (ext) => `-${n++}${ext || ""}`);
|
||||
}
|
||||
usedNames.add(cand.toLowerCase());
|
||||
return cand;
|
||||
}
|
||||
|
||||
/**
|
||||
* สร้าง ZIP ของ "ทุกรูปในโฟลเดอร์" + metadata.json
|
||||
* ใช้ compression: STORE เพราะ JPEG บีบอัดต่อไม่ได้แล้ว (เร็วขึ้นมากบนมือถือ)
|
||||
* ZIP ของโฟลเดอร์เดียว — ทุกรูปอยู่ในโฟลเดอร์ชื่อเดียวกับโฟลเดอร์
|
||||
* compression STORE เพราะ JPEG บีบอัดต่อไม่ได้แล้ว
|
||||
*/
|
||||
export async function buildZip(folder, images, onProgress) {
|
||||
if (!window.JSZip) throw new Error("JSZip not loaded");
|
||||
const zip = new JSZip();
|
||||
const base = entryBase(folder);
|
||||
const photos = [];
|
||||
const dir = folderDirName(folder, new Set());
|
||||
const used = new Set();
|
||||
|
||||
zip.folder(dir);
|
||||
images.forEach((img, idx) => {
|
||||
const seq = String(idx + 1).padStart(4, "0");
|
||||
const name = img.name || `${base}_${seq}.jpg`;
|
||||
zip.file(name, img.blob);
|
||||
photos.push({ file: name, ...(img.meta || {}) });
|
||||
const fallback = `${entryBase(folder)}_${String(idx + 1).padStart(4, "0")}.jpg`;
|
||||
zip.file(`${dir}/${uniqueEntryName(img.name || fallback, used)}`, img.blob);
|
||||
});
|
||||
|
||||
zip.file(
|
||||
"metadata.json",
|
||||
JSON.stringify(
|
||||
{
|
||||
folder: folder.name,
|
||||
count: images.length,
|
||||
generated_at: new Date().toISOString(),
|
||||
generated_at_th: humanDateTime(Date.now()),
|
||||
app: "CamCat 2.0.0",
|
||||
photos,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
|
||||
const blob = await zip.generateAsync({ type: "blob", compression: "STORE" }, (m) => {
|
||||
if (onProgress) onProgress(m.percent);
|
||||
});
|
||||
|
||||
const fileName = safeFileName(folder.name, "photos") + ".zip";
|
||||
const file = new File([blob], fileName, { type: "application/zip" });
|
||||
return { blob, file, fileName };
|
||||
return { blob, file, fileName, dir, photos: images.length };
|
||||
}
|
||||
|
||||
/** ใช้ cache ถ้ารายการรูปไม่เปลี่ยน — ทำให้กดแชร์แล้วเปิด share sheet ได้ทันที */
|
||||
/**
|
||||
* ZIP รวมทุกโฟลเดอร์ในครั้งเดียว — แต่ละโฟลเดอร์เป็นโฟลเดอร์ย่อยของตัวเอง
|
||||
* folders: [{id,name,...}] · imagesByFolder: { [folderId]: images[] }
|
||||
*/
|
||||
export async function buildAllZip(folders, imagesByFolder, onProgress) {
|
||||
if (!window.JSZip) throw new Error("JSZip not loaded");
|
||||
const zip = new JSZip();
|
||||
const usedDirs = new Set();
|
||||
let photos = 0;
|
||||
let folderCount = 0;
|
||||
|
||||
folders.forEach((folder) => {
|
||||
const images = imagesByFolder[folder.id] || [];
|
||||
const dir = folderDirName(folder, usedDirs);
|
||||
zip.folder(dir); // สร้างโฟลเดอร์แม้ยังไม่มีรูป
|
||||
folderCount++;
|
||||
const used = new Set();
|
||||
images.forEach((img, idx) => {
|
||||
const fallback = `${entryBase(folder)}_${String(idx + 1).padStart(4, "0")}.jpg`;
|
||||
zip.file(`${dir}/${uniqueEntryName(img.name || fallback, used)}`, img.blob);
|
||||
photos++;
|
||||
});
|
||||
});
|
||||
|
||||
const blob = await zip.generateAsync({ type: "blob", compression: "STORE" }, (m) => {
|
||||
if (onProgress) onProgress(m.percent);
|
||||
});
|
||||
|
||||
const fileName = `CamCat-all-${fileStamp()}.zip`;
|
||||
const file = new File([blob], fileName, { type: "application/zip" });
|
||||
return { blob, file, fileName, folders: folderCount, photos };
|
||||
}
|
||||
|
||||
/** ใช้ cache ถ้ารายการรูปไม่เปลี่ยน */
|
||||
export async function ensureZip(folder, images, onProgress, { force = false } = {}) {
|
||||
const sig = signatureOf(folder, images);
|
||||
if (!force && cache.file && cache.signature === sig) return cache;
|
||||
@@ -65,6 +104,14 @@ export async function ensureZip(folder, images, onProgress, { force = false } =
|
||||
return cache;
|
||||
}
|
||||
|
||||
/** คืน File ที่สร้างไว้แล้วถ้ารายการรูปยังไม่เปลี่ยน */
|
||||
export function peekZip(folder, images) {
|
||||
try {
|
||||
if (folder && cache.file && cache.signature === signatureOf(folder, images)) return cache.file;
|
||||
} catch { /* ignore */ }
|
||||
return null;
|
||||
}
|
||||
|
||||
export function invalidateZip() {
|
||||
cache.signature = "";
|
||||
cache.file = null;
|
||||
@@ -92,10 +139,7 @@ export function downloadFile(file) {
|
||||
setTimeout(() => URL.revokeObjectURL(url), 60_000);
|
||||
}
|
||||
|
||||
/**
|
||||
* แชร์ผ่าน Web Share API ระดับไฟล์ → share sheet ของ Samsung → เลือกแอปปลายทาง
|
||||
* คืน {ok, reason}
|
||||
*/
|
||||
/** แชร์ผ่าน Web Share API ระดับไฟล์ — คืน {ok, reason} */
|
||||
export async function shareFile(file, { title, text } = {}) {
|
||||
if (!navigator.share) return { ok: false, reason: "unsupported" };
|
||||
const payload = { files: [file], title: title || file.name, text: text || "" };
|
||||
@@ -107,6 +151,10 @@ export async function shareFile(file, { title, text } = {}) {
|
||||
return { ok: true };
|
||||
} catch (err) {
|
||||
if (err && err.name === "AbortError") return { ok: false, reason: "cancelled" };
|
||||
if (err && (err.name === "NotAllowedError" || err.name === "InvalidStateError")) {
|
||||
return { ok: false, reason: "notallowed", error: err };
|
||||
}
|
||||
if (err && err.name === "TypeError") return { ok: false, reason: "nofiles", error: err };
|
||||
return { ok: false, reason: "failed", error: err };
|
||||
}
|
||||
}
|
||||
@@ -125,6 +125,30 @@ export async function setZoom(value) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* บังคับให้เป็น JPEG จริง — EXIF ฝังได้เฉพาะ JPEG
|
||||
* (ImageCapture บางเครื่อง/บางเวอร์ชันคืน PNG กลับมา)
|
||||
*/
|
||||
async function toJpegBlob(blob, quality = JPEG_QUALITY) {
|
||||
if (!blob) return blob;
|
||||
const head = new Uint8Array(await blob.slice(0, 3).arrayBuffer());
|
||||
const isJpeg = head[0] === 0xff && head[1] === 0xd8;
|
||||
if (isJpeg) return blob.type === "image/jpeg" ? blob : new Blob([blob], { type: "image/jpeg" });
|
||||
|
||||
try {
|
||||
const bmp = await createImageBitmap(blob);
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = bmp.width;
|
||||
canvas.height = bmp.height;
|
||||
canvas.getContext("2d").drawImage(bmp, 0, 0);
|
||||
bmp.close?.();
|
||||
const out = await new Promise((res) => canvas.toBlob(res, "image/jpeg", quality));
|
||||
return out || blob;
|
||||
} catch {
|
||||
return blob;
|
||||
}
|
||||
}
|
||||
|
||||
async function makeThumb(blob) {
|
||||
try {
|
||||
const bmp = await createImageBitmap(blob);
|
||||
@@ -142,18 +166,57 @@ async function makeThumb(blob) {
|
||||
}
|
||||
|
||||
/**
|
||||
* ถ่ายภาพนิ่ง
|
||||
/** ครอปกลางภาพให้ได้อัตราส่วนที่เลือก (4:3 = 1.333, 3:4 = 0.75) */
|
||||
async function cropToRatio(blob, ratio) {
|
||||
try {
|
||||
const bmp = await createImageBitmap(blob);
|
||||
const w = bmp.width, h = bmp.height;
|
||||
const src = w / h;
|
||||
let sw = w, sh = h, sx = 0, sy = 0;
|
||||
if (src > ratio + 0.002) {
|
||||
sw = Math.round(h * ratio);
|
||||
sx = Math.round((w - sw) / 2);
|
||||
} else if (src < ratio - 0.002) {
|
||||
sh = Math.round(w / ratio);
|
||||
sy = Math.round((h - sh) / 2);
|
||||
}
|
||||
if (sw === w && sh === h) { bmp.close?.(); return { blob, width: w, height: h }; }
|
||||
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = sw;
|
||||
canvas.height = sh;
|
||||
canvas.getContext("2d").drawImage(bmp, sx, sy, sw, sh, 0, 0, sw, sh);
|
||||
bmp.close?.();
|
||||
const out = await new Promise((res) => canvas.toBlob(res, "image/jpeg", JPEG_QUALITY));
|
||||
return { blob: out || blob, width: sw, height: sh };
|
||||
} catch {
|
||||
return { blob, width: 0, height: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
function ratioValue(label) {
|
||||
const m = /^(\d+)\s*[:x/]\s*(\d+)$/.exec(String(label || ""));
|
||||
if (!m) return 4 / 3;
|
||||
const a = Number(m[1]), b = Number(m[2]);
|
||||
return b ? a / b : 4 / 3;
|
||||
}
|
||||
|
||||
/** ถ่ายภาพนิ่ง
|
||||
* 1) ImageCapture.takePhoto() — ได้ JPEG ความละเอียดเต็มเซนเซอร์ + EXIF จากกล้อง (S23)
|
||||
* 2) fallback: วาดเฟรมวิดีโอลง canvas
|
||||
*/
|
||||
export async function captureStill() {
|
||||
export async function captureStill({ ratio = "4:3" } = {}) {
|
||||
if (!cam.track) throw camError("notready");
|
||||
let blob = null;
|
||||
let source = "canvas";
|
||||
|
||||
if (cam.imageCapture) {
|
||||
try {
|
||||
blob = await cam.imageCapture.takePhoto();
|
||||
// บางเครื่อง takePhoto() ค้างไม่ resolve → กันด้วย timeout แล้วตกไปใช้ canvas
|
||||
blob = await Promise.race([
|
||||
cam.imageCapture.takePhoto(),
|
||||
new Promise((_, rej) => setTimeout(() => rej(new Error("takePhoto timeout")), 4000)),
|
||||
]);
|
||||
source = "imagecapture";
|
||||
} catch { blob = null; }
|
||||
}
|
||||
@@ -171,6 +234,11 @@ export async function captureStill() {
|
||||
source = "canvas";
|
||||
}
|
||||
|
||||
// EXIF ฝังได้เฉพาะ JPEG → แปลงถ้าจำเป็น (ก่อนอ่านขนาด/ทำ thumb)
|
||||
blob = await toJpegBlob(blob);
|
||||
|
||||
// ครอป/จัดทิศทางทำที่ main.js (หลัง auto-orient) — ที่นี่คืนภาพดิบ
|
||||
|
||||
if (!width || !height) {
|
||||
try {
|
||||
const bmp = await createImageBitmap(blob);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// ── ค่าคงที่ทั้งแอป ──────────────────────────────────────────
|
||||
export const APP_VERSION = "2.0.0";
|
||||
export const APP_VERSION = "2.1.4";
|
||||
export const DB_NAME = "camcat-db";
|
||||
export const DB_VERSION = 2;
|
||||
|
||||
export const SITE_LABEL = "Site A"; // ชื่อไซต์ ใช้เป็น prefix ของโฟลเดอร์
|
||||
export const SITE_LABEL = "Site"; // prefix ของโฟลเดอร์ (ตัวอักษร a-z ต่อท้าย)
|
||||
export const TIME_ZONE = "Asia/Bangkok"; // ปี พ.ศ. คำนวณจากโซนนี้เสมอ
|
||||
|
||||
export const JPEG_QUALITY = 0.92;
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
// ── นำเข้าโฟลเดอร์ทีละหลายรายการจาก CSV ─────────────────────
|
||||
// หัวตาราง: site,letter,datetime,name
|
||||
// site : คำนำหน้า (เว้นว่าง = "Site")
|
||||
// letter : ตัวอักษร a-z/aa… (เว้นว่าง = ไล่ต่อจากของเดิมอัตโนมัติ)
|
||||
// datetime : 2569.10.25.21.45 (รับ – / : ช่องว่าง หรือ ค.ศ. ได้)
|
||||
// name : ชื่อเต็ม (ถ้าใส่ จะใช้ค่านี้แทนการประกอบชื่อ)
|
||||
import { SITE_LABEL } from "./config.js";
|
||||
import { safeFileName, letterForIndex, indexForLetters, nextLetter, normalizeFolderStamp } from "./naming.js";
|
||||
|
||||
const DELIMS = [",", ";", "\t"];
|
||||
|
||||
function sniffDelimiter(line) {
|
||||
let best = ",";
|
||||
let bestCount = -1;
|
||||
for (const d of DELIMS) {
|
||||
const n = line.split(d).length - 1;
|
||||
if (n > bestCount) { best = d; bestCount = n; }
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/** CSV → array ของ object (คีย์เป็นตัวพิมพ์เล็ก) รองรับ quote/CRLF/BOM */
|
||||
export function parseCsv(text) {
|
||||
const src = String(text || "").replace(/^\uFEFF/, "").replace(/\r\n?/g, "\n").trim();
|
||||
if (!src) return { header: [], rows: [] };
|
||||
|
||||
const delim = sniffDelimiter(src.split("\n")[0]);
|
||||
const rows = [];
|
||||
let field = "";
|
||||
let row = [];
|
||||
let quoted = false;
|
||||
|
||||
for (let i = 0; i < src.length; i++) {
|
||||
const ch = src[i];
|
||||
if (quoted) {
|
||||
if (ch === '"') {
|
||||
if (src[i + 1] === '"') { field += '"'; i++; }
|
||||
else quoted = false;
|
||||
} else field += ch;
|
||||
continue;
|
||||
}
|
||||
if (ch === '"') { quoted = true; continue; }
|
||||
if (ch === delim) { row.push(field); field = ""; continue; }
|
||||
if (ch === "\n") { row.push(field); rows.push(row); row = []; field = ""; continue; }
|
||||
field += ch;
|
||||
}
|
||||
if (field.length || row.length) { row.push(field); rows.push(row); }
|
||||
|
||||
const header = rows.shift().map((h) => h.trim().toLowerCase());
|
||||
const out = rows
|
||||
.filter((r) => r.some((c) => String(c).trim() !== ""))
|
||||
.map((r) => {
|
||||
const obj = {};
|
||||
header.forEach((h, idx) => { obj[h] = (r[idx] ?? "").trim(); });
|
||||
return obj;
|
||||
});
|
||||
return { header, rows: out, delimiter: delim };
|
||||
}
|
||||
|
||||
/**
|
||||
* วางแผนสร้างโฟลเดอร์จากแถว CSV
|
||||
* คืน { items:[{name,row}], errors:[{row,reason}] }
|
||||
*/
|
||||
export function planFolders(rows, existingNames = []) {
|
||||
const taken = new Set(existingNames.map((n) => String(n)));
|
||||
const items = [];
|
||||
const errors = [];
|
||||
let nextIdx = Math.max(0, indexForLetters(nextLetter(existingNames))); // ตัวอักษรถัดไป (a ถ้ายังไม่มี)
|
||||
|
||||
rows.forEach((row, i) => {
|
||||
const line = i + 2; // +2 = เผื่อหัวตาราง (เริ่มนับที่ 1)
|
||||
const rawName = (row.name || "").trim();
|
||||
|
||||
let site = (row.site || SITE_LABEL).trim() || SITE_LABEL;
|
||||
site = site.replace(/\s+/g, " ");
|
||||
|
||||
let letter = (row.letter || "").trim().toLowerCase();
|
||||
if (letter && !/^[a-z]+$/.test(letter)) {
|
||||
errors.push({ row: line, reason: `letter "${row.letter}" ไม่ใช่ a-z` });
|
||||
return;
|
||||
}
|
||||
|
||||
const stamp = normalizeFolderStamp(row.datetime, null);
|
||||
if (row.datetime && !stamp) {
|
||||
errors.push({ row: line, reason: `datetime "${row.datetime}" อ่านไม่ได้ (ต้องเป็น ปี.เดือน.วัน.ชั่วโมง.นาที)` });
|
||||
return;
|
||||
}
|
||||
|
||||
let name = rawName ? safeFileName(rawName, "") : "";
|
||||
if (!name) {
|
||||
if (!stamp) {
|
||||
errors.push({ row: line, reason: "ไม่มี datetime และไม่มี name" });
|
||||
return;
|
||||
}
|
||||
if (!letter) {
|
||||
// หา letter ว่างถัดไป (ข้ามชื่อที่มีอยู่แล้ว)
|
||||
let guard = 0;
|
||||
do { letter = letterForIndex(nextIdx++); guard++; } while (taken.has(`${site} ${letter} ${stamp}`) && guard < 500);
|
||||
}
|
||||
name = `${site} ${letter} ${stamp}`;
|
||||
}
|
||||
|
||||
if (!name) { errors.push({ row: line, reason: "ชื่อว่าง" }); return; }
|
||||
if (taken.has(name)) { errors.push({ row: line, reason: `ชื่อซ้ำ: ${name}` }); return; }
|
||||
|
||||
taken.add(name);
|
||||
items.push({ name, row: line });
|
||||
});
|
||||
|
||||
return { items, errors };
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// ── อ่าน/เขียน EXIF (JPEG) ด้วย piexifjs ─────────────────────
|
||||
// Metadata ที่ฝังในไฟล์จะติดไปกับรูปตอนแชร์ออกแอปอื่นด้วย
|
||||
// เป้าหมาย: metadata อยู่ใน "ไฟล์รูป" แบบเดียวกับแอปกล้องของ Samsung
|
||||
// (Make/Model/เวลา/GPS/ความละเอียด ฯลฯ ฝังใน EXIF — ไม่มีไฟล์ JSON แยก)
|
||||
|
||||
const piexif = () => (typeof window !== "undefined" ? window.piexif : undefined);
|
||||
|
||||
@@ -33,9 +34,13 @@ const dmsToDecimal = (dms, ref) => {
|
||||
return ref === "S" || ref === "W" ? -v : v;
|
||||
};
|
||||
|
||||
const str = (v) => (typeof v === "string" ? v.replace(/\0+$/, "").trim() : undefined);
|
||||
const str = (v) => {
|
||||
if (typeof v !== "string") return undefined;
|
||||
const s = v.replace(/\0+$/, "").trim();
|
||||
return s || undefined;
|
||||
};
|
||||
|
||||
/** อ่าน EXIF จาก JPEG → object แบน (ค่าว่าง = ไม่มี tag) */
|
||||
/** อ่าน EXIF จาก JPEG → object แบน (คีย์ไม่มี = ไฟล์ไม่มี tag นั้น) */
|
||||
export async function readExif(blob) {
|
||||
const px = piexif();
|
||||
if (!px || !blob) return {};
|
||||
@@ -44,28 +49,42 @@ export async function readExif(blob) {
|
||||
if (!dataUrl.startsWith("data:image/jpeg")) return {};
|
||||
const exif = px.load(dataUrl) || {};
|
||||
const o = exif["0th"] || {};
|
||||
const e = exif["Exif"] || {};
|
||||
const g = exif["GPS"] || {};
|
||||
const e = exif.Exif || {};
|
||||
const g = exif.GPS || {};
|
||||
return {
|
||||
make: str(o[271]),
|
||||
model: str(o[272]),
|
||||
description: str(o[270]),
|
||||
software: str(o[305]),
|
||||
dateTime: str(o[306]) || str(e[36867]),
|
||||
dateTime: str(o[306]),
|
||||
dateTimeOriginal: str(e[36867]),
|
||||
dateTimeDigitized: str(e[36868]),
|
||||
orientation: typeof o[274] === "number" ? o[274] : undefined,
|
||||
xResolution: o[282] ? rat(o[282]) : undefined,
|
||||
resolutionUnit: o[296],
|
||||
colorSpace: e[40961],
|
||||
exifVersion: str(e[36864]),
|
||||
uniqueId: str(e[42016]),
|
||||
width: e[40962] || o[256] || undefined,
|
||||
height: e[40963] || o[257] || undefined,
|
||||
iso: typeof e[34855] === "number" ? e[34855] : undefined,
|
||||
fNumber: e[33437] ? rat(e[33437]) : undefined,
|
||||
exposureTime: e[33434] ? rat(e[33434]) : undefined,
|
||||
exposureBias: e[37380] ? rat(e[37380]) : undefined,
|
||||
focalLength: e[37386] ? rat(e[37386]) : undefined,
|
||||
lensModel: str(e[42036]),
|
||||
lensMake: str(e[42035]),
|
||||
hasMakerNote: !!e[37500],
|
||||
xpComment: fromUtf16le(o[40092]),
|
||||
xpKeywords: fromUtf16le(o[40094]),
|
||||
gps: g[2] ? {
|
||||
lat: dmsToDecimal(g[2], str(g[1])),
|
||||
lng: dmsToDecimal(g[4], str(g[3])),
|
||||
altitude: g[6] ? rat(g[6]) * (str(g[5]) === "1" ? -1 : 1) : null,
|
||||
accuracy: g[31] ? rat(g[31]) : null,
|
||||
dateStamp: str(g[29]),
|
||||
timeStamp: Array.isArray(g[7]) ? g[7].map(rat) : null,
|
||||
processingMethod: str(g[27]),
|
||||
} : null,
|
||||
};
|
||||
} catch {
|
||||
@@ -73,6 +92,48 @@ export async function readExif(blob) {
|
||||
}
|
||||
}
|
||||
|
||||
/** ตัดอักษรนอก ASCII ออกให้หมด (ใช้กับชื่อที่ต้องอ่านรู้เรื่อง) */
|
||||
const asciiStripped = (s, fallback = "CamCat") => {
|
||||
const v = String(s ?? "").normalize("NFC").replace(/[^\x20-\x7E]/g, "").replace(/\s{2,}/g, " ").trim();
|
||||
return v || fallback;
|
||||
};
|
||||
|
||||
/** EXIF ASCII รับได้เฉพาะ Latin1 — แทนอักษรนอกช่วงด้วย ? (ชื่อไทยเก็บใน XPComment แทน) */
|
||||
const ascii = (s, fallback = "") => {
|
||||
const v = String(s ?? "").normalize("NFC").replace(/[^\x20-\x7E]/g, "?").trim();
|
||||
return v || fallback;
|
||||
};
|
||||
|
||||
/** XP* tags เก็บ Unicode แบบ UTF-16LE เป็น array ของ byte */
|
||||
const utf16le = (s) => {
|
||||
const out = [];
|
||||
for (const ch of String(s ?? "")) {
|
||||
const code = ch.codePointAt(0);
|
||||
if (code > 0xffff) {
|
||||
const v = code - 0x10000;
|
||||
const hi = 0xd800 + (v >> 10);
|
||||
const lo = 0xdc00 + (v & 0x3ff);
|
||||
out.push(hi & 0xff, hi >> 8, lo & 0xff, lo >> 8);
|
||||
} else {
|
||||
out.push(code & 0xff, code >> 8);
|
||||
}
|
||||
}
|
||||
out.push(0, 0); // null terminator
|
||||
return out;
|
||||
};
|
||||
|
||||
const fromUtf16le = (bytes) => {
|
||||
if (!Array.isArray(bytes) || !bytes.length) return undefined;
|
||||
const codes = [];
|
||||
for (let i = 0; i + 1 < bytes.length; i += 2) {
|
||||
const c = bytes[i] | (bytes[i + 1] << 8);
|
||||
if (c === 0) break;
|
||||
codes.push(c);
|
||||
}
|
||||
if (!codes.length) return undefined;
|
||||
try { return String.fromCharCode(...codes); } catch { return undefined; }
|
||||
};
|
||||
|
||||
const decToDms = (dec) => {
|
||||
const abs = Math.abs(dec);
|
||||
const d = Math.floor(abs);
|
||||
@@ -82,52 +143,118 @@ const decToDms = (dec) => {
|
||||
return [[d, 1], [m, 1], [s, 100]];
|
||||
};
|
||||
|
||||
/** แยก "YYYY:MM:DD HH:MM:SS" เพื่อใช้กับ GPSTimeStamp/GPSDateStamp */
|
||||
function splitDateTime(dateTime) {
|
||||
const m = /^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})$/.exec(dateTime || "");
|
||||
if (!m) return null;
|
||||
return { date: `${m[1]}:${m[2]}:${m[3]}`, h: +m[4], mi: +m[5], s: +m[6] };
|
||||
}
|
||||
|
||||
/**
|
||||
* ฝัง EXIF ลง JPEG ก่อนบันทึก
|
||||
* meta = { make, model, dateTime, gps:{lat,lng,altitude}, width, height, folder, source }
|
||||
* คืน Blob ใหม่ (ถ้าฝังไม่ได้คืน blob เดิม)
|
||||
* ฝัง EXIF มาตรฐานลง JPEG (แบบที่แอปกล้อง Samsung เขียน)
|
||||
* meta = {
|
||||
* make, model, modelName, software, dateTime,
|
||||
* width, height, folder, orientation, uniqueId,
|
||||
* gps: { lat, lng, altitude, accuracy },
|
||||
* iso, fNumber, exposureTime, focalLength // ใส่เฉพาะที่มีค่าจริง
|
||||
* }
|
||||
* คืน Blob ใหม่ — ถ้าเขียนไม่ได้คืน blob เดิม
|
||||
*/
|
||||
export async function writeExif(blob, meta = {}) {
|
||||
const px = piexif();
|
||||
if (!px || !blob || blob.type !== "image/jpeg") return blob;
|
||||
|
||||
try {
|
||||
const dataUrl = await blobToDataURL(blob);
|
||||
let existing = {};
|
||||
try { existing = px.load(dataUrl) || {}; } catch { existing = {}; }
|
||||
|
||||
const zeroth = Object.assign({}, existing["0th"] || {});
|
||||
const exif = Object.assign({}, existing["Exif"] || {});
|
||||
const gps = Object.assign({}, existing["GPS"] || {});
|
||||
const zeroth = { ...(existing["0th"] || {}) };
|
||||
const exif = { ...(existing.Exif || {}) };
|
||||
const gps = { ...(existing.GPS || {}) };
|
||||
|
||||
zeroth[271] = meta.make || "Samsung";
|
||||
zeroth[272] = meta.model || "Samsung Galaxy S23";
|
||||
zeroth[305] = "CamCat " + (meta.version || "2.0.0");
|
||||
zeroth[306] = meta.dateTime;
|
||||
if (meta.folder) zeroth[270] = "Folder: " + meta.folder; // ImageDescription (IFD0)
|
||||
if (!zeroth[274]) zeroth[274] = 1;
|
||||
// ── IFD0 (ASCII เท่านั้น) ──
|
||||
const fullLabel = meta.folder ? `CamCat · ${meta.folder}` : "CamCat";
|
||||
zeroth[270] = asciiStripped(fullLabel, "CamCat"); // ImageDescription
|
||||
zeroth[271] = ascii(meta.make, "samsung"); // Make
|
||||
zeroth[272] = ascii(meta.model || meta.modelName, "CamCat Web"); // Model
|
||||
zeroth[305] = ascii(meta.software, "CamCat"); // Software
|
||||
zeroth[315] = asciiStripped(meta.folder || "CamCat", "CamCat"); // Artist = ชื่อโฟลเดอร์
|
||||
// ชื่อที่มีอักษรไทย/Unicode → เก็บใน XPComment (UTF-16LE) และ XPKeywords
|
||||
if (/[^\x20-\x7E]/.test(String(meta.folder || ""))) {
|
||||
zeroth[40092] = utf16le(fullLabel); // XPComment
|
||||
zeroth[40094] = utf16le(meta.folder); // XPKeywords
|
||||
}
|
||||
if (meta.dateTime) zeroth[306] = meta.dateTime;
|
||||
zeroth[274] = meta.orientation || 1; // บังคับค่าหลัง normalize แล้ว
|
||||
zeroth[282] = [72, 1];
|
||||
zeroth[283] = [72, 1];
|
||||
zeroth[296] = 2;
|
||||
zeroth[296] = 2; // นิ้ว
|
||||
|
||||
exif[36867] = meta.dateTime; // DateTimeOriginal
|
||||
exif[36868] = meta.dateTime; // DateTimeDigitized
|
||||
// ── Exif IFD ──
|
||||
exif[36864] = "0232"; // ExifVersion (Undefined 4 ไบต์)
|
||||
if (meta.dateTime) {
|
||||
exif[36867] = meta.dateTime; // DateTimeOriginal
|
||||
exif[36868] = meta.dateTime; // DateTimeDigitized
|
||||
}
|
||||
exif[37121] = "\x01\x02\x03\x00"; // ComponentsConfiguration = YCbCr
|
||||
exif[40961] = 1; // ColorSpace = sRGB
|
||||
if (meta.width) exif[40962] = meta.width;
|
||||
if (meta.height) exif[40963] = meta.height;
|
||||
exif[37380] = [0, 1]; // ExposureBiasValue
|
||||
exif[41985] = 0; // CustomRendered: normal
|
||||
exif[41986] = 0; // ExposureMode: auto
|
||||
exif[41987] = 0; // WhiteBalance: auto
|
||||
exif[41988] = [1, 1]; // DigitalZoomRatio
|
||||
exif[41990] = 0; // SceneCaptureType: standard
|
||||
exif[41992] = 0; // Contrast: normal
|
||||
exif[41993] = 0; // Saturation: normal
|
||||
exif[41994] = 0; // Sharpness: normal
|
||||
if (meta.uniqueId) exif[42016] = ascii(meta.uniqueId).slice(0, 32);
|
||||
|
||||
if (meta.gps && Number.isFinite(meta.gps.lat) && Number.isFinite(meta.gps.lng)) {
|
||||
// ค่าที่วัดได้จริงเท่านั้น (ไม่เดา)
|
||||
if (Number.isFinite(meta.iso) && meta.iso > 0) exif[34855] = Math.round(meta.iso);
|
||||
if (Number.isFinite(meta.fNumber) && meta.fNumber > 0) exif[33437] = [Math.round(meta.fNumber * 10), 10];
|
||||
if (Number.isFinite(meta.exposureTime) && meta.exposureTime > 0) {
|
||||
exif[33434] = meta.exposureTime >= 1
|
||||
? [Math.round(meta.exposureTime * 100), 100]
|
||||
: [1, Math.round(1 / meta.exposureTime)];
|
||||
}
|
||||
if (Number.isFinite(meta.focalLength) && meta.focalLength > 0) exif[37386] = [Math.round(meta.focalLength * 10), 10];
|
||||
if (meta.lensModel) exif[42036] = ascii(meta.lensModel);
|
||||
|
||||
// ── GPS IFD ──
|
||||
const g = meta.gps;
|
||||
if (g && Number.isFinite(g.lat) && Number.isFinite(g.lng)) {
|
||||
const dt = splitDateTime(meta.dateTime);
|
||||
gps[0] = [2, 3, 0, 0];
|
||||
gps[1] = meta.gps.lat >= 0 ? "N" : "S";
|
||||
gps[2] = decToDms(meta.gps.lat);
|
||||
gps[3] = meta.gps.lng >= 0 ? "E" : "W";
|
||||
gps[4] = decToDms(meta.gps.lng);
|
||||
if (Number.isFinite(meta.gps.altitude)) {
|
||||
gps[5] = meta.gps.altitude >= 0 ? 0 : 1;
|
||||
gps[6] = [Math.round(Math.abs(meta.gps.altitude) * 100), 100];
|
||||
gps[1] = g.lat >= 0 ? "N" : "S";
|
||||
gps[2] = decToDms(g.lat);
|
||||
gps[3] = g.lng >= 0 ? "E" : "W";
|
||||
gps[4] = decToDms(g.lng);
|
||||
if (Number.isFinite(g.altitude)) {
|
||||
gps[5] = g.altitude >= 0 ? 0 : 1;
|
||||
gps[6] = [Math.round(Math.abs(g.altitude) * 100), 100];
|
||||
}
|
||||
gps[29] = meta.dateTime.slice(0, 10).replace(/:/g, ":");
|
||||
if (Number.isFinite(g.accuracy) && g.accuracy > 0) {
|
||||
gps[31] = [Math.round(g.accuracy * 100), 100]; // GPSHPositioningError (เมตร)
|
||||
}
|
||||
if (dt) {
|
||||
gps[7] = [[dt.h, 1], [dt.mi, 1], [dt.s, 1]]; // GPSTimeStamp
|
||||
gps[29] = dt.date; // GPSDateStamp
|
||||
}
|
||||
gps[27] = "ASCII\x00\x00\x00GPS"; // GPSProcessingMethod
|
||||
}
|
||||
|
||||
const dict = { "0th": zeroth, Exif: exif, GPS: gps, Interop: existing.Interop || {}, "1st": existing["1st"] || {}, thumbnail: null };
|
||||
const dict = {
|
||||
"0th": zeroth,
|
||||
Exif: exif,
|
||||
GPS: gps,
|
||||
Interop: existing.Interop || {},
|
||||
"1st": existing["1st"] || {},
|
||||
thumbnail: existing.thumbnail || null,
|
||||
};
|
||||
|
||||
const inserted = px.insert(px.dump(dict), dataUrl);
|
||||
return dataURLToBlob(inserted);
|
||||
} catch (err) {
|
||||
@@ -136,7 +263,7 @@ export async function writeExif(blob, meta = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 1/125 · f/1.8 · 50mm */
|
||||
/** "1/125 · f/1.8 · ISO 50 · 5mm" */
|
||||
export function formatExposure(exif = {}) {
|
||||
const bits = [];
|
||||
if (exif.fNumber) bits.push("f/" + exif.fNumber.toFixed(1));
|
||||
|
||||
@@ -11,10 +11,14 @@ import { detectDevice, exifModelName, environment } from "./device.js";
|
||||
import {
|
||||
defaultFolderName, exifDateString, safeFileName, uniqueName,
|
||||
} from "./naming.js";
|
||||
import { ensureZip, invalidateZip, downloadFile, shareFile, canShareFiles } from "./archive.js";
|
||||
import { ensureZip, peekZip, invalidateZip, downloadFile, shareFile, canShareFiles, buildAllZip } from "./archive.js";
|
||||
import { parseCsv, planFolders } from "./csv.js";
|
||||
import * as native from "./native.js";
|
||||
import { autoOrient, detectOrientation, cropToRatio, ratioValue, makeThumbFromBlob, rotateBlob } from "./orient.js";
|
||||
|
||||
const LS_FOLDER = "camcat.activeFolder";
|
||||
const LS_FACING = "camcat.facing";
|
||||
const LS_RATIO = "camcat.ratio";
|
||||
|
||||
const state = {
|
||||
view: "camera",
|
||||
@@ -30,7 +34,9 @@ const state = {
|
||||
zoomRange: null,
|
||||
zoomValue: null,
|
||||
grid: false,
|
||||
ratio: localStorage.getItem(LS_RATIO) || "4:3",
|
||||
busy: false,
|
||||
lastZip: null,
|
||||
facing: localStorage.getItem(LS_FACING) || "environment",
|
||||
storage: null,
|
||||
};
|
||||
@@ -105,6 +111,11 @@ function flash() {
|
||||
setTimeout(() => el.remove(), 220);
|
||||
}
|
||||
|
||||
function newUniqueId(ts = Date.now()) {
|
||||
const rnd = () => Math.floor(Math.random() * 0xffff).toString(16).padStart(4, "0");
|
||||
return (ts.toString(16) + rnd().repeat(8)).padEnd(32, "0").slice(0, 32);
|
||||
}
|
||||
|
||||
function nextFileName(folderName, images) {
|
||||
const base = safeFileName(folderName).replace(/\s+/g, "_");
|
||||
let max = 0;
|
||||
@@ -142,6 +153,20 @@ async function getGps() {
|
||||
}
|
||||
|
||||
// ── camera view ─────────────────────────────────────────────
|
||||
function fitFrame() {
|
||||
const stage = document.querySelector(".stage");
|
||||
const frame = document.getElementById("cam-frame");
|
||||
if (!stage || !frame) return;
|
||||
const box = stage.getBoundingClientRect();
|
||||
if (!box.width || !box.height) return;
|
||||
const r = state.ratio === "3:4" ? 3 / 4 : 4 / 3;
|
||||
let w = box.width;
|
||||
let h = w / r;
|
||||
if (h > box.height) { h = box.height; w = h * r; }
|
||||
frame.style.width = Math.round(w) + "px";
|
||||
frame.style.height = Math.round(h) + "px";
|
||||
}
|
||||
|
||||
function syncCam(overrides = {}) {
|
||||
ui.syncCameraControls({
|
||||
torchAvailable: state.torchAvailable && state.camReady,
|
||||
@@ -150,10 +175,13 @@ function syncCam(overrides = {}) {
|
||||
zoomValue: state.zoomValue,
|
||||
gridOn: state.grid,
|
||||
count: state.images.length,
|
||||
ratio: state.ratio,
|
||||
thumbUrl: state.images.length ? thumbUrl(state.images[state.images.length - 1]) : null,
|
||||
ready: state.camReady,
|
||||
...overrides,
|
||||
});
|
||||
fitFrame();
|
||||
setTimeout(fitFrame, 80);
|
||||
}
|
||||
|
||||
function renderCameraView() {
|
||||
@@ -274,6 +302,12 @@ async function switchCamera() {
|
||||
}
|
||||
|
||||
// ── shoot ───────────────────────────────────────────────────
|
||||
const withTimeout = (p, ms, label) =>
|
||||
Promise.race([
|
||||
p,
|
||||
new Promise((_, rej) => setTimeout(() => rej(new Error(label + " timeout")), ms)),
|
||||
]);
|
||||
|
||||
async function shoot() {
|
||||
if (state.busy) return;
|
||||
if (!state.camReady) { ui.toast("กล้องยังไม่พร้อม"); return; }
|
||||
@@ -281,25 +315,61 @@ async function shoot() {
|
||||
const shutter = document.getElementById("shutter");
|
||||
if (shutter) shutter.disabled = true;
|
||||
|
||||
// watchdog: บางเครื่อง promise ของกล้องค้าง → ปลดล็อกปุ่มเอง
|
||||
const watchdog = setTimeout(() => {
|
||||
state.busy = false;
|
||||
const s = document.getElementById("shutter");
|
||||
if (s) s.disabled = false;
|
||||
ui.toast("ถ่ายใช้เวลานานเกินไป — ลองอีกครั้ง");
|
||||
}, 20000);
|
||||
|
||||
try {
|
||||
const folder = state.folder;
|
||||
if (!folder) throw new Error("ยังไม่มีโฟลเดอร์");
|
||||
|
||||
const shot = await camApi.captureStill();
|
||||
const gps = await getGps();
|
||||
const at = Date.now();
|
||||
const exifBlob = await writeExif(shot.blob, {
|
||||
make: "Samsung",
|
||||
model: exifModelName(),
|
||||
dateTime: exifDateString(new Date(at)),
|
||||
gps,
|
||||
const shot = await Promise.race([
|
||||
camApi.captureStill(),
|
||||
new Promise((_, rej) => setTimeout(() => rej(new Error("capture timeout")), 12000)),
|
||||
]);
|
||||
|
||||
// ① อ่าน EXIF Orientation ของไฟล์ แล้วหมุนพิกเซลให้ตั้งตรง (Orientation = 1)
|
||||
const orientationTag = await detectOrientation(shot.blob);
|
||||
const oriented = await autoOrient({
|
||||
blob: shot.blob,
|
||||
exifOrientation: orientationTag,
|
||||
width: shot.width,
|
||||
height: shot.height,
|
||||
folder: folder.name,
|
||||
source: shot.source,
|
||||
version: APP_VERSION,
|
||||
facing: shot.facing,
|
||||
});
|
||||
const exifRead = await readExif(exifBlob);
|
||||
|
||||
// ② ครอปตามอัตราส่วนที่เลือก (ทำหลังจัดทิศทาง เพื่อไม่ให้ครอปผิดแกน)
|
||||
const cropped = await cropToRatio(oriented.blob, ratioValue(state.ratio));
|
||||
const finalBlob = cropped.blob;
|
||||
const fw = cropped.width || oriented.width || shot.width;
|
||||
const fh = cropped.height || oriented.height || shot.height;
|
||||
const thumb = await makeThumbFromBlob(finalBlob);
|
||||
|
||||
const gps = await getGps();
|
||||
const at = Date.now();
|
||||
const isSamsung = /^SM-/i.test(device.code) || device.brand === "Samsung";
|
||||
const exifBlob = await writeExif(finalBlob, {
|
||||
make: isSamsung ? "samsung" : device.brand || "CamCat",
|
||||
model: /^SM-/i.test(device.code)
|
||||
? device.code
|
||||
: /^[\x20-\x7E]+$/.test(device.model || "")
|
||||
? device.model
|
||||
: "CamCat Web Camera",
|
||||
modelName: exifModelName(),
|
||||
software: `CamCat ${APP_VERSION} | Android ${device.androidVersion || "-"} | Chrome ${device.chromeVersion || "-"}`,
|
||||
dateTime: exifDateString(new Date(at)),
|
||||
gps,
|
||||
width: fw,
|
||||
height: fh,
|
||||
folder: folder.name,
|
||||
orientation: 1,
|
||||
uniqueId: newUniqueId(at),
|
||||
});
|
||||
const exifRead = await withTimeout(readExif(exifBlob), 6000, "readExif");
|
||||
const name = nextFileName(folder.name, state.images);
|
||||
|
||||
const record = {
|
||||
@@ -307,17 +377,22 @@ async function shoot() {
|
||||
folderId: folder.id,
|
||||
name,
|
||||
blob: exifBlob,
|
||||
thumb: shot.thumb,
|
||||
thumb: thumb,
|
||||
size: exifBlob.size,
|
||||
createdAt: at,
|
||||
meta: {
|
||||
width: shot.width,
|
||||
height: shot.height,
|
||||
width: fw,
|
||||
height: fh,
|
||||
ratio: state.ratio,
|
||||
orientationTag,
|
||||
rotationApplied: oriented.rotation || 0,
|
||||
mirrored: !!oriented.mirrored,
|
||||
device: exifModelName(),
|
||||
facing: shot.facing,
|
||||
facingLabel: shot.facing === "environment" ? "กล้องหลัง" : "กล้องหน้า",
|
||||
source: shot.source,
|
||||
sourceLabel: shot.source === "imagecapture" ? "ImageCapture (ความละเอียดเต็ม)" : "วิดีโอ (canvas)",
|
||||
orientSource: oriented.source,
|
||||
gps: gps ? { lat: gps.lat, lng: gps.lng, accuracy: gps.accuracy } : null,
|
||||
exif: exifRead,
|
||||
app: `CamCat ${APP_VERSION}`,
|
||||
@@ -325,24 +400,76 @@ async function shoot() {
|
||||
},
|
||||
};
|
||||
|
||||
await db.putImage(record);
|
||||
await db.touchFolder(folder.id);
|
||||
await withTimeout(db.putImage(record), 8000, "db.putImage");
|
||||
await withTimeout(db.touchFolder(folder.id), 5000, "db.touchFolder");
|
||||
state.images.push(record);
|
||||
state.counts = state.counts.map((c, i) => (state.folders[i]?.id === folder.id ? c + 1 : c));
|
||||
|
||||
flash();
|
||||
invalidateZip();
|
||||
syncCam({ thumbUrl: thumbUrl(record) });
|
||||
ui.toast(`บันทึก ${name} · ${shot.width}×${shot.height}`);
|
||||
|
||||
let savedTo = "";
|
||||
if (native.isNative()) {
|
||||
const uri = await native.savePhoto(folder.name, name, exifBlob);
|
||||
if (uri) savedTo = ` → ${native.displayPath(folder.name)}`;
|
||||
}
|
||||
ui.toast(`บันทึก ${name}${savedTo}`);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
ui.toast("ถ่ายไม่สำเร็จ: " + (err.code || err.message));
|
||||
} finally {
|
||||
clearTimeout(watchdog);
|
||||
state.busy = false;
|
||||
if (shutter) shutter.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function rotatePhoto(id, deg) {
|
||||
const rec = await db.getImage(id);
|
||||
if (!rec) return;
|
||||
try {
|
||||
const out = await rotateBlob(rec.blob, deg);
|
||||
const at = rec.createdAt;
|
||||
const folderName = rec.meta?.folder || state.folder?.name || "";
|
||||
const exifBlob = await writeExif(out.blob, {
|
||||
make: rec.meta?.exif?.make || "samsung",
|
||||
model: rec.meta?.exif?.model || "SM-S911B",
|
||||
software: rec.meta?.exif?.software || `CamCat ${APP_VERSION}`,
|
||||
dateTime: exifDateString(new Date(at)),
|
||||
width: out.width,
|
||||
height: out.height,
|
||||
folder: folderName,
|
||||
orientation: 1,
|
||||
uniqueId: rec.meta?.exif?.uniqueId || newUniqueId(at),
|
||||
gps: rec.meta?.gps
|
||||
? { lat: rec.meta.gps.lat, lng: rec.meta.gps.lng, accuracy: rec.meta.gps.accuracy }
|
||||
: null,
|
||||
});
|
||||
|
||||
rec.blob = exifBlob;
|
||||
rec.thumb = out.thumb;
|
||||
rec.size = exifBlob.size;
|
||||
rec.meta = {
|
||||
...(rec.meta || {}),
|
||||
width: out.width,
|
||||
height: out.height,
|
||||
rotationApplied: (((rec.meta?.rotationApplied || 0) + deg) % 360 + 360) % 360,
|
||||
rotatedManually: true,
|
||||
exif: await readExif(exifBlob),
|
||||
};
|
||||
await db.putImage(rec);
|
||||
state.images = state.images.map((i) => (i.id === id ? rec : i));
|
||||
dropThumb(id);
|
||||
invalidateZip();
|
||||
await openPhoto(id);
|
||||
ui.toast(`หมุน ${deg > 0 ? "ขวา" : "ซ้าย"} 90° แล้ว`);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
ui.toast("หมุนรูปไม่สำเร็จ: " + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// ── folder data ─────────────────────────────────────────────
|
||||
async function loadFolders() {
|
||||
state.folders = await db.getFolders();
|
||||
@@ -363,7 +490,7 @@ async function selectFolder(id, { silent = false } = {}) {
|
||||
async function ensureDefaultFolder() {
|
||||
await loadFolders();
|
||||
if (!state.folders.length) {
|
||||
const folder = { id: "f_" + Date.now(), name: defaultFolderName(), createdAt: Date.now(), updatedAt: Date.now() };
|
||||
const folder = { id: "f_" + Date.now(), name: defaultFolderName(state.folders.map((f) => f.name)), createdAt: Date.now(), updatedAt: Date.now() };
|
||||
await db.putFolder(folder);
|
||||
await loadFolders();
|
||||
await selectFolder(folder.id, { silent: true });
|
||||
@@ -438,43 +565,105 @@ function schedulePrebuild() {
|
||||
}, 1200);
|
||||
}
|
||||
|
||||
async function buildZipFile() {
|
||||
const { file } = await ensureZip(state.folder, state.images, (p) =>
|
||||
ui.progressUpdate(p, `กำลังรวม ${state.images.length} รูป`)
|
||||
);
|
||||
state.lastZip = file;
|
||||
return file;
|
||||
}
|
||||
|
||||
function sharePayload(file) {
|
||||
return {
|
||||
title: state.folder?.name || file.name,
|
||||
text: `รูปจาก ${state.folder?.name || ""} (${state.images.length} รูป)`,
|
||||
};
|
||||
}
|
||||
|
||||
function shareReasonText(reason) {
|
||||
if (reason === "notallowed") return "เบราว์เซอร์ตัดสิทธิ์เพราะรอนาน — แตะอีกครั้ง";
|
||||
if (reason === "nofiles") return "เบราว์เซอร์นี้ไม่รองรับการแชร์ไฟล์";
|
||||
if (reason === "notsupported" || reason === "unsupported") return "ไม่มี Web Share API";
|
||||
if (reason === "failed") return "ระบบแชร์ปฏิเสธ";
|
||||
return "";
|
||||
}
|
||||
|
||||
function showShareSheet(file, reason = "") {
|
||||
ui.openSheet(
|
||||
ui.shareReadySheet({
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
canShare: canShareFiles(file) && !!navigator.share,
|
||||
reason: shareReasonText(reason),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
async function handleShareResult(res, file) {
|
||||
if (res.ok) { ui.closeSheet(); ui.toast("เปิด share sheet ของเครื่องแล้ว"); return; }
|
||||
if (res.reason === "cancelled") { ui.closeSheet(); return; }
|
||||
showShareSheet(file, res.reason);
|
||||
}
|
||||
|
||||
async function deliverFile(file, note = "") {
|
||||
if (native.isNative()) {
|
||||
const uri = await native.saveZip(file);
|
||||
if (uri) {
|
||||
ui.toast(`บันทึก ${file.name} ลง Documents/CamCat-ZIP${note ? " · " + note : ""}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
downloadFile(file);
|
||||
ui.toast(`ดาวน์โหลด ${file.name} (${ui.fmtBytes(file.size)})${note ? " · " + note : ""}`);
|
||||
}
|
||||
|
||||
async function zipFlow(mode) {
|
||||
if (!state.folder) { ui.toast("ยังไม่เลือกโฟลเดอร์"); return; }
|
||||
if (!state.images.length) { ui.toast("ยังไม่มีรูปในโฟลเดอร์นี้"); return; }
|
||||
if (state.busy) return;
|
||||
state.busy = true;
|
||||
|
||||
ui.progressSheet(`กำลังรวม ${state.images.length} รูปเป็น ZIP`);
|
||||
try {
|
||||
const { file } = await ensureZip(state.folder, state.images, (p) =>
|
||||
ui.progressUpdate(p, `กำลังรวม ${state.images.length} รูป`)
|
||||
);
|
||||
ui.closeSheet();
|
||||
|
||||
if (mode === "download") {
|
||||
downloadFile(file);
|
||||
ui.toast(`ดาวน์โหลด ${file.name} (${ui.fmtBytes(file.size)})`);
|
||||
const cached = peekZip(state.folder, state.images);
|
||||
let file = cached;
|
||||
if (!file) {
|
||||
ui.progressSheet(`กำลังรวม ${state.images.length} รูปเป็น ZIP`);
|
||||
file = await buildZipFile();
|
||||
ui.closeSheet();
|
||||
}
|
||||
await deliverFile(file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canShareFiles(file)) {
|
||||
downloadFile(file);
|
||||
ui.toast("เครื่องนี้แชร์ไฟล์ผ่านเว็บไม่ได้ — ดาวน์โหลด ZIP ให้แล้ว");
|
||||
// APK: ใช้ share sheet ของ Android ผ่านปลั๊กอิน Share (FileProvider)
|
||||
if (native.isNative()) {
|
||||
let file = peekZip(state.folder, state.images);
|
||||
if (!file) {
|
||||
ui.progressSheet(`กำลังรวม ${state.images.length} รูปเป็น ZIP`);
|
||||
file = await buildZipFile();
|
||||
ui.closeSheet();
|
||||
}
|
||||
const res = await native.shareItems([{ name: file.name, blob: file }], state.folder?.name || "");
|
||||
if (res.ok) { ui.closeSheet(); ui.toast("แชร์ผ่านระบบของ Android แล้ว"); }
|
||||
else if (res.reason === "cancelled") { ui.closeSheet(); }
|
||||
else { await deliverFile(file); }
|
||||
return;
|
||||
}
|
||||
const res = await shareFile(file, {
|
||||
title: state.folder.name,
|
||||
text: `รูปจาก ${state.folder.name} (${state.images.length} รูป)`,
|
||||
});
|
||||
if (res.ok) ui.toast("เปิดเมนูแชร์ของเครื่องแล้ว");
|
||||
else if (res.reason === "cancelled") ui.toast("ยกเลิกการแชร์");
|
||||
else if (res.reason === "unsupported" || res.reason === "nofiles") {
|
||||
downloadFile(file);
|
||||
ui.toast("แชร์ไฟล์ไม่ได้ — ดาวน์โหลด ZIP ให้แล้ว");
|
||||
} else {
|
||||
downloadFile(file);
|
||||
ui.toast("แชร์ไม่สำเร็จ — ดาวน์โหลด ZIP ให้แล้ว");
|
||||
|
||||
// แชร์: ถ้ามี ZIP ที่สร้างไว้แล้ว → ยิง share ทันทีในจังหวะแตะ (activation ยังสด)
|
||||
const cached = peekZip(state.folder, state.images);
|
||||
if (cached) {
|
||||
const res = await shareFile(cached, sharePayload(cached));
|
||||
await handleShareResult(res, cached);
|
||||
return;
|
||||
}
|
||||
|
||||
// ยังไม่มี ZIP → สร้างก่อน แล้วให้ผู้ใช้แตะแชร์อีกครั้ง (activation ใหม่)
|
||||
ui.progressSheet(`กำลังรวม ${state.images.length} รูปเป็น ZIP`);
|
||||
const file = await buildZipFile();
|
||||
ui.closeSheet();
|
||||
showShareSheet(file, "");
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
ui.closeSheet();
|
||||
@@ -484,6 +673,53 @@ async function zipFlow(mode) {
|
||||
}
|
||||
}
|
||||
|
||||
// ZIP ทุกโฟลเดอร์ในครั้งเดียว (แยกโฟลเดอร์ย่อยในไฟล์ zip)
|
||||
async function zipAllFolders() {
|
||||
if (state.busy) return;
|
||||
await loadFolders();
|
||||
if (!state.folders.length) { ui.toast("ยังไม่มีโฟลเดอร์"); return; }
|
||||
|
||||
const byFolder = {};
|
||||
let total = 0;
|
||||
for (const f of state.folders) {
|
||||
const imgs = await db.getImages(f.id);
|
||||
byFolder[f.id] = imgs;
|
||||
total += imgs.length;
|
||||
}
|
||||
if (!total) { ui.toast("ยังไม่มีรูปในทุกโฟลเดอร์"); return; }
|
||||
|
||||
state.busy = true;
|
||||
ui.progressSheet(`กำลังรวม ${state.folders.length} โฟลเดอร์ (${total} รูป)`);
|
||||
try {
|
||||
const { file, photos, folders } = await buildAllZip(state.folders, byFolder, (p) =>
|
||||
ui.progressUpdate(p, `กำลังรวม ${total} รูป`)
|
||||
);
|
||||
ui.closeSheet();
|
||||
await deliverFile(file, `${folders} โฟลเดอร์ ${photos} รูป`);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
ui.closeSheet();
|
||||
ui.toast("สร้าง ZIP รวมไม่สำเร็จ: " + err.message);
|
||||
} finally {
|
||||
state.busy = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function shareCachedZip() {
|
||||
const file = peekZip(state.folder, state.images) || state.lastZip;
|
||||
if (!file) { ui.toast("ยังไม่มีไฟล์ ZIP"); return; }
|
||||
const res = await shareFile(file, sharePayload(file));
|
||||
await handleShareResult(res, file);
|
||||
}
|
||||
|
||||
function saveCachedZip() {
|
||||
const file = peekZip(state.folder, state.images) || state.lastZip;
|
||||
if (!file) { ui.toast("ยังไม่มีไฟล์ ZIP"); return; }
|
||||
downloadFile(file);
|
||||
ui.closeSheet();
|
||||
ui.toast(`บันทึก ${file.name} ลงเครื่องแล้ว`);
|
||||
}
|
||||
|
||||
// ── photo sheet ─────────────────────────────────────────────
|
||||
async function openPhoto(id) {
|
||||
const rec = await db.getImage(id);
|
||||
@@ -509,6 +745,12 @@ async function deletePhoto(id) {
|
||||
async function shareOnePhoto(id) {
|
||||
const rec = await db.getImage(id);
|
||||
if (!rec) return;
|
||||
|
||||
if (native.isNative()) {
|
||||
const res = await native.shareItems([{ name: rec.name || "photo.jpg", blob: rec.blob }], rec.name || "");
|
||||
ui.toast(res.ok ? "แชร์ผ่านระบบของ Android แล้ว" : res.reason === "cancelled" ? "ยกเลิก" : "แชร์ไม่สำเร็จ");
|
||||
return;
|
||||
}
|
||||
const file = new File([rec.blob], rec.name || "photo.jpg", { type: "image/jpeg" });
|
||||
if (!canShareFiles(file)) {
|
||||
downloadFile(file);
|
||||
@@ -533,6 +775,9 @@ async function showDiagnostics() {
|
||||
["visualViewport", env.visualViewport],
|
||||
["จอจริง (px)", env.screen],
|
||||
["โหมดติดตั้ง", env.standalone ? "PWA (standalone)" : "เบราว์เซอร์"],
|
||||
["โหมดแอป", native.nativeInfo().label],
|
||||
["ปุ่มเสียง", native.isNative() ? "กดถ่ายรูปได้ (Volume up/down)" : "ใช้ได้เฉพาะใน APK"],
|
||||
["ที่เก็บไฟล์", native.isNative() ? "Documents/CamCat (โฟลเดอร์จริงในเครื่อง)" : "Download ของเบราว์เซอร์"],
|
||||
["ความปลอดภัย", env.secureContext ? "HTTPS — ใช้กล้องได้" : "ไม่ปลอดภัย — กล้องถูกบล็อก"],
|
||||
["URL", env.url],
|
||||
["สตรีมกล้อง", s.width ? `${s.width}×${s.height} @${Math.round(s.frameRate || 0)}fps` : "ยังไม่เปิด"],
|
||||
@@ -576,11 +821,67 @@ async function copyLink() {
|
||||
}
|
||||
}
|
||||
|
||||
// ── สร้างโฟลเดอร์เร็ว / นำเข้า CSV ───────────────────────────
|
||||
async function quickCreateFolder() {
|
||||
await loadFolders();
|
||||
const name = defaultFolderName(state.folders.map((f) => f.name));
|
||||
const folder = { id: "f_" + Date.now(), name, createdAt: Date.now(), updatedAt: Date.now() };
|
||||
await db.putFolder(folder);
|
||||
await selectFolder(folder.id, { silent: true });
|
||||
await loadFolders();
|
||||
await render();
|
||||
ui.toast("สร้าง " + name + " — เปลี่ยนชื่อได้ที่ปุ่มดินสอ");
|
||||
}
|
||||
|
||||
function pickCsvFile() {
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.accept = ".csv,text/csv,text/plain";
|
||||
input.style.display = "none";
|
||||
input.addEventListener("change", async () => {
|
||||
const file = input.files && input.files[0];
|
||||
input.remove();
|
||||
if (!file) return;
|
||||
try {
|
||||
const text = await file.text();
|
||||
const { rows } = parseCsv(text);
|
||||
if (!rows.length) { ui.toast("ไฟล์ CSV ไม่มีแถวข้อมูล"); return; }
|
||||
|
||||
await loadFolders();
|
||||
const { items, errors } = planFolders(rows, state.folders.map((f) => f.name));
|
||||
const now = Date.now();
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
await db.putFolder({ id: `f_${now}_${i}`, name: items[i].name, createdAt: now + i, updatedAt: now + i });
|
||||
}
|
||||
await loadFolders();
|
||||
|
||||
if (items.length) {
|
||||
const first = state.folders.find((f) => f.name === items[0].name);
|
||||
if (first) await selectFolder(first.id, { silent: true });
|
||||
}
|
||||
await render();
|
||||
ui.openSheet(
|
||||
ui.importResultSheet({
|
||||
created: items.length,
|
||||
skipped: errors.length,
|
||||
errors,
|
||||
total: rows.length,
|
||||
})
|
||||
);
|
||||
if (items.length) ui.toast(`สร้าง ${items.length} โฟลเดอร์จาก CSV`);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
ui.toast("อ่านไฟล์ CSV ไม่สำเร็จ: " + err.message);
|
||||
}
|
||||
});
|
||||
document.body.appendChild(input);
|
||||
input.click();
|
||||
}
|
||||
|
||||
// ── folder modals ───────────────────────────────────────────
|
||||
async function openNewFolder() {
|
||||
await loadFolders();
|
||||
const base = defaultFolderName();
|
||||
const suggested = uniqueName(base, state.folders.map((f) => f.name));
|
||||
const suggested = defaultFolderName(state.folders.map((f) => f.name));
|
||||
ui.openSheet(ui.folderSheet("new", { suggested }));
|
||||
setTimeout(() => document.getElementById("folder-name-input")?.select(), 60);
|
||||
}
|
||||
@@ -636,7 +937,7 @@ async function confirmDeleteFolder(id) {
|
||||
if (state.folder?.id === id) {
|
||||
if (state.folders.length) await selectFolder(state.folders[0].id, { silent: true });
|
||||
else {
|
||||
const folder = { id: "f_" + Date.now(), name: defaultFolderName(), createdAt: Date.now(), updatedAt: Date.now() };
|
||||
const folder = { id: "f_" + Date.now(), name: defaultFolderName(state.folders.map((f) => f.name)), createdAt: Date.now(), updatedAt: Date.now() };
|
||||
await db.putFolder(folder);
|
||||
await loadFolders();
|
||||
await selectFolder(folder.id, { silent: true });
|
||||
@@ -665,6 +966,13 @@ document.addEventListener("click", async (e) => {
|
||||
syncCam();
|
||||
break;
|
||||
}
|
||||
case "toggle-ratio": {
|
||||
state.ratio = state.ratio === "4:3" ? "3:4" : "4:3";
|
||||
localStorage.setItem(LS_RATIO, state.ratio);
|
||||
syncCam();
|
||||
ui.toast("อัตราส่วนภาพ " + state.ratio + " (บันทึกแล้ว)");
|
||||
break;
|
||||
}
|
||||
case "toggle-grid":
|
||||
state.grid = !state.grid;
|
||||
syncCam();
|
||||
@@ -677,6 +985,12 @@ document.addEventListener("click", async (e) => {
|
||||
await render();
|
||||
break;
|
||||
case "new-folder": await openNewFolder(); break;
|
||||
case "quick-new-folder": await quickCreateFolder(); break;
|
||||
case "csv-sheet": ui.openSheet(ui.csvSheet()); break;
|
||||
case "pick-csv": pickCsvFile(); break;
|
||||
case "zip-all": await zipAllFolders(); break;
|
||||
case "share-zip-now": await shareCachedZip(); break;
|
||||
case "save-zip": saveCachedZip(); break;
|
||||
case "rename-folder": openRenameFolder(id); break;
|
||||
case "delete-folder": {
|
||||
const f = state.folders.find((x) => x.id === id);
|
||||
@@ -690,6 +1004,7 @@ document.addEventListener("click", async (e) => {
|
||||
case "open-photo": await openPhoto(id); break;
|
||||
case "delete-photo": await deletePhoto(id); break;
|
||||
case "share-photo": await shareOnePhoto(id); break;
|
||||
case "rotate-photo": await rotatePhoto(id, Number(el.dataset.dir || 90)); break;
|
||||
case "zip-download": await zipFlow("download"); break;
|
||||
case "zip-share": await zipFlow("share"); break;
|
||||
case "diagnostics": await showDiagnostics(); break;
|
||||
@@ -746,6 +1061,11 @@ async function init() {
|
||||
document.getElementById("app").dataset.view = state.view;
|
||||
renderCameraView();
|
||||
|
||||
// ล็อกแนวตั้ง (APK) — กัน UI หมุนตามตอนถือแนวนอนแล้วถ่ายไม่ได้
|
||||
if (native.isNative() && screen.orientation && screen.orientation.lock) {
|
||||
try { await screen.orientation.lock("portrait"); } catch { /* เว็บจะThrow — ข้าม */ }
|
||||
}
|
||||
|
||||
const wanted = new URLSearchParams(location.search).get("view");
|
||||
if (wanted === "gallery" || wanted === "folders") {
|
||||
await navigate(wanted);
|
||||
@@ -760,4 +1080,20 @@ async function init() {
|
||||
}
|
||||
}
|
||||
|
||||
// ปุ่มเพิ่ม/ลดเสียง (ส่งมาจาก MainActivity ใน APK) = ชัตเตอร์
|
||||
let lastVolumeShot = 0;
|
||||
window.addEventListener("camcat:shutter", () => {
|
||||
const now = Date.now();
|
||||
if (now - lastVolumeShot < 600) return; // กดค้าง/กดรัว
|
||||
lastVolumeShot = now;
|
||||
if (state.view !== "camera" || !state.camReady || state.busy) return;
|
||||
if (navigator.vibrate) { try { navigator.vibrate(12); } catch { /* ignore */ } }
|
||||
shoot();
|
||||
});
|
||||
|
||||
window.addEventListener("resize", () => fitFrame());
|
||||
window.addEventListener("orientationchange", () => setTimeout(fitFrame, 250));
|
||||
window.addEventListener("DOMContentLoaded", init);
|
||||
|
||||
// เปิดให้ตรวจสถานะภายในได้ (ใช้ตอน debug บนเครื่องจริง)
|
||||
window.__camcat = { state, cam, native, version: APP_VERSION };
|
||||
@@ -23,10 +23,65 @@ export function bkkParts(date = new Date()) {
|
||||
};
|
||||
}
|
||||
|
||||
/** "Site A 2569-10-24" */
|
||||
export function defaultFolderName(date = new Date()) {
|
||||
/** "2569.10.25.21.45" — ปี พ.ศ..เดือน.วัน.ชั่วโมง.นาที */
|
||||
export function folderStamp(date = new Date()) {
|
||||
const p = bkkParts(date);
|
||||
return `${SITE_LABEL} ${p.thaiYear}-${p.month}-${p.day}`;
|
||||
return `${p.thaiYear}.${p.month}.${p.day}.${p.hour}.${p.minute}`;
|
||||
}
|
||||
|
||||
/** 0→a, 25→z, 26→aa, 27→ab … (แบบคอลัมน์ Excel) */
|
||||
export function letterForIndex(index) {
|
||||
let n = Math.max(0, Math.trunc(index)) + 1;
|
||||
let s = "";
|
||||
while (n > 0) {
|
||||
const r = (n - 1) % 26;
|
||||
s = String.fromCharCode(97 + r) + s;
|
||||
n = Math.floor((n - 1) / 26);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/** a→0, z→25, aa→26 … (คืน -1 ถ้าไม่ใช่ a-z ล้วน) */
|
||||
export function indexForLetters(letters) {
|
||||
const s = String(letters || "").trim().toLowerCase();
|
||||
if (!/^[a-z]+$/.test(s)) return -1;
|
||||
let n = 0;
|
||||
for (const ch of s) n = n * 26 + (ch.charCodeAt(0) - 97 + 1);
|
||||
return n - 1;
|
||||
}
|
||||
|
||||
/** ตัวอักษรถัดไปจากชื่อโฟลเดอร์ที่มีอยู่: Site a …, Site b … */
|
||||
export function nextLetter(existingNames = []) {
|
||||
let max = -1;
|
||||
for (const name of existingNames) {
|
||||
const m = /^site\s+([a-z]+)\s+\d/.exec(String(name).toLowerCase());
|
||||
if (m) max = Math.max(max, indexForLetters(m[1]));
|
||||
}
|
||||
return letterForIndex(max + 1);
|
||||
}
|
||||
|
||||
/** ประกอบชื่อ: Site <letter> <stamp> */
|
||||
export function makeFolderName({ site = SITE_LABEL, letter = "a", date = new Date(), datetime } = {}) {
|
||||
return `${site} ${letter} ${datetime || folderStamp(date)}`;
|
||||
}
|
||||
|
||||
/** ชื่อเริ่มต้นของโฟลเดอร์ใหม่ (ไล่ตัวอักษรอัตโนมัติ) */
|
||||
export function defaultFolderName(existingNames = [], date = new Date()) {
|
||||
return makeFolderName({ letter: nextLetter(existingNames), date });
|
||||
}
|
||||
|
||||
/** ตรวจ/ทำความสะอาดค่า datetime จาก CSV → "2569.10.25.21.45" (คืน null ถ้าใช้ไม่ได้) */
|
||||
export function normalizeFolderStamp(input, fallback = null) {
|
||||
const raw = String(input ?? "").trim();
|
||||
if (!raw) return fallback;
|
||||
const nums = raw.match(/\d+/g);
|
||||
if (!nums || nums.length < 3) return null;
|
||||
const [y, mo, d, h = "0", mi = "0"] = nums.map((x) => Number(x));
|
||||
const year = y > 2400 ? y : y + 543; // รับทั้ง ค.ศ. และ พ.ศ.
|
||||
if (year < 2400 || year > 2700) return null;
|
||||
if (mo < 1 || mo > 12 || d < 1 || d > 31 || h > 23 || mi > 59) return null;
|
||||
const p2 = (n) => String(n).padStart(2, "0");
|
||||
return `${year}.${p2(mo)}.${p2(d)}.${p2(h)}.${p2(mi)}`;
|
||||
}
|
||||
|
||||
/** EXIF DateTimeOriginal: "YYYY:MM:DD HH:MM:SS" (เวลาไทย) */
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
// ── Native bridge (Capacitor / Android APK) ───────────────────
|
||||
// ทำงานเมื่อรันใน APK เท่านั้น — บนเว็บทุกฟังก์ชันคืน null แล้วแอปใช้ทางเดิม
|
||||
// ต้องมีปลั๊กอิน: @capacitor/filesystem, @capacitor/share
|
||||
|
||||
const cap = () => (typeof window !== "undefined" ? window.Capacitor : undefined);
|
||||
|
||||
export function isNative() {
|
||||
try {
|
||||
return !!(cap() && typeof cap().isNativePlatform === "function" && cap().isNativePlatform());
|
||||
} catch { return false; }
|
||||
}
|
||||
|
||||
export function platform() {
|
||||
try { return cap()?.getPlatform?.() || "web"; } catch { return "web"; }
|
||||
}
|
||||
|
||||
function plugin(name) {
|
||||
return cap()?.Plugins?.[name] || null;
|
||||
}
|
||||
|
||||
const MAX_NAME = 120;
|
||||
|
||||
function safeSeg(s, fallback = "file") {
|
||||
const v = String(s ?? "")
|
||||
.replace(/[\\/:*?"<>|\u0000-\u001f]/g, "-")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim()
|
||||
.replace(/^\.+/, "");
|
||||
return (v || fallback).slice(0, MAX_NAME);
|
||||
}
|
||||
|
||||
let lastDirLabel = "";
|
||||
export function displayPath(folderName) {
|
||||
return `${lastDirLabel || "Documents"}/CamCat/${safeSeg(folderName, "folder")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* เขียนไฟล์โดยไล่ directory ที่ใช้ได้:
|
||||
* DOCUMENTS (Android ≤10 / เข้าถึงจากแอปอื่นได้) → EXTERNAL (app-specific, ใช้ได้ทุกเวอร์ชัน)
|
||||
*/
|
||||
async function writeWithFallback(fs, path, data) {
|
||||
const tries = [
|
||||
{ directory: "DOCUMENTS", label: "Documents" },
|
||||
{ directory: "EXTERNAL", label: "Android/data/…/files" },
|
||||
];
|
||||
let lastErr = null;
|
||||
for (const t of tries) {
|
||||
try {
|
||||
const res = await fs.writeFile({ path, data, directory: t.directory, recursive: true });
|
||||
lastDirLabel = t.label;
|
||||
return res?.uri || "ok";
|
||||
} catch (err) { lastErr = err; }
|
||||
}
|
||||
throw lastErr || new Error("write failed");
|
||||
}
|
||||
|
||||
function blobToBase64(blob) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const r = new FileReader();
|
||||
r.onload = () => {
|
||||
const s = String(r.result || "");
|
||||
resolve(s.slice(s.indexOf(",") + 1));
|
||||
};
|
||||
r.onerror = () => reject(r.error);
|
||||
r.readAsDataURL(blob);
|
||||
});
|
||||
}
|
||||
|
||||
/** เขียนรูปลงโฟลเดอร์จริงบนเครื่อง: Documents/CamCat/<โฟลเดอร์>/<ไฟล์>.jpg */
|
||||
export async function savePhoto(folderName, fileName, blob) {
|
||||
if (!isNative()) return null;
|
||||
const fs = plugin("Filesystem");
|
||||
if (!fs) return null;
|
||||
try {
|
||||
const data = await blobToBase64(blob);
|
||||
return await writeWithFallback(fs, `CamCat/${safeSeg(folderName, "folder")}/${safeSeg(fileName, "photo.jpg")}`, data);
|
||||
} catch (err) {
|
||||
console.warn("native savePhoto failed", err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** เขียนไฟล์ ZIP ลง Documents/CamCat-ZIP */
|
||||
export async function saveZip(file) {
|
||||
if (!isNative()) return null;
|
||||
const fs = plugin("Filesystem");
|
||||
if (!fs) return null;
|
||||
try {
|
||||
const data = await blobToBase64(file);
|
||||
return await writeWithFallback(fs, `CamCat-ZIP/${safeSeg(file.name, "photos.zip")}`, data);
|
||||
} catch (err) {
|
||||
console.warn("native saveZip failed", err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* แชร์ไฟล์ (รูปเดี่ยว/หลายรูป/ZIP) ผ่าน share sheet ของ Android
|
||||
* items = [{ name, blob }]
|
||||
* หมายเหตุ: Android แชร์ "โฟลเดอร์" ทั้งโฟลเดอร์เป็น URI ไม่ได้ → ใช้หลายไฟล์ หรือ ZIP
|
||||
*/
|
||||
export async function shareItems(items, title = "") {
|
||||
if (!isNative()) return { ok: false, reason: "notnative" };
|
||||
const fs = plugin("Filesystem");
|
||||
const share = plugin("Share");
|
||||
if (!fs || !share) return { ok: false, reason: "noplugin" };
|
||||
|
||||
try {
|
||||
const uris = [];
|
||||
for (const it of items) {
|
||||
const data = await blobToBase64(it.blob);
|
||||
const res = await fs.writeFile({
|
||||
path: `share/${Date.now()}-${safeSeg(it.name, "file")}`,
|
||||
data,
|
||||
directory: "CACHE",
|
||||
recursive: true,
|
||||
});
|
||||
if (res?.uri) uris.push(res.uri);
|
||||
}
|
||||
if (!uris.length) return { ok: false, reason: "nofiles" };
|
||||
|
||||
await share.share({
|
||||
title: title || (items.length === 1 ? items[0].name : "CamCat"),
|
||||
dialogTitle: title || "แชร์ด้วย",
|
||||
files: uris,
|
||||
});
|
||||
return { ok: true };
|
||||
} catch (err) {
|
||||
const msg = String(err?.message || err);
|
||||
if (/cancel/i.test(msg)) return { ok: false, reason: "cancelled" };
|
||||
console.warn("native share failed", err);
|
||||
return { ok: false, reason: "failed", error: err };
|
||||
}
|
||||
}
|
||||
|
||||
/** จำนวนไฟล์ที่บันทึกลงเครื่องแล้ว (ใช้โชว์ใน diagnostics) */
|
||||
export function nativeInfo() {
|
||||
return {
|
||||
native: isNative(),
|
||||
platform: platform(),
|
||||
label: isNative() ? `APK (${platform()})` : "เว็บ / PWA",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
// ── จัดการทิศทางภาพ (auto-orient) ─────────────────────────────
|
||||
// เป้าหมาย: รูปที่ถ่าย/แชร์ออกไปต้องตั้งตรงทุกแอป แม้แอปปลายทางไม่สนใจ EXIF
|
||||
// วิธี: อ่าน EXIF Orientation → หมุนพิกเซลให้ตรง → เขียน Orientation = 1 กลับ
|
||||
import { JPEG_QUALITY, THUMB_MAX, THUMB_QUALITY } from "./config.js";
|
||||
import { blobToDataURL, dataURLToBlob } from "./exif.js";
|
||||
|
||||
/** ตาราง EXIF orientation 1-8 → การแปลงเพื่อให้ภาพตั้งตรง */
|
||||
export const ORIENTATION_MATRIX = {
|
||||
1: { rotate: 0, mirror: false },
|
||||
2: { rotate: 0, mirror: true },
|
||||
3: { rotate: 180, mirror: false },
|
||||
4: { rotate: 180, mirror: true },
|
||||
5: { rotate: 90, mirror: true },
|
||||
6: { rotate: 90, mirror: false },
|
||||
7: { rotate: 270, mirror: true },
|
||||
8: { rotate: 270, mirror: false },
|
||||
};
|
||||
|
||||
/** อ่านค่า Orientation จาก JPEG โดยตรง (fallback ถ้า piexif ไม่มี) */
|
||||
export function readOrientationTag(bytes) {
|
||||
try {
|
||||
const u8 = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
||||
if (u8[0] !== 0xff || u8[1] !== 0xd8) return 1;
|
||||
let i = 2;
|
||||
while (i < u8.length - 4) {
|
||||
if (u8[i] !== 0xff) { i++; continue; }
|
||||
const marker = u8[i + 1];
|
||||
const len = (u8[i + 2] << 8) | u8[i + 3];
|
||||
if (marker === 0xe1 && u8[i + 4] === 0x45 && u8[i + 5] === 0x78) {
|
||||
const tiff = i + 10;
|
||||
const little = u8[tiff] === 0x49;
|
||||
const rd16 = (o) => (little ? u8[o] | (u8[o + 1] << 8) : (u8[o] << 8) | u8[o + 1]);
|
||||
const rd32 = (o) => (little
|
||||
? u8[o] | (u8[o + 1] << 8) | (u8[o + 2] << 16) | (u8[o + 3] << 24)
|
||||
: (u8[o] << 24) | (u8[o + 1] << 16) | (u8[o + 2] << 8) | u8[o + 3]) >>> 0;
|
||||
const ifd0 = tiff + rd32(tiff + 4);
|
||||
const count = rd16(ifd0);
|
||||
for (let k = 0; k < count; k++) {
|
||||
const entry = ifd0 + 2 + k * 12;
|
||||
if (rd16(entry) === 0x0112) return rd16(entry + 8);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
i += 2 + len;
|
||||
}
|
||||
return 1;
|
||||
} catch { return 1; }
|
||||
}
|
||||
|
||||
/** อ่านขนาดจริงจากหัวไฟล์ JPEG (SOF) — ใช้ตรวจว่าเบราว์เซอร์หมุนให้แล้วหรือยัง */
|
||||
export async function jpegSize(blob) {
|
||||
try {
|
||||
const u8 = new Uint8Array(await blob.slice(0, 65536).arrayBuffer());
|
||||
if (u8[0] !== 0xff || u8[1] !== 0xd8) return null;
|
||||
let i = 2;
|
||||
while (i < u8.length - 9) {
|
||||
if (u8[i] !== 0xff) { i++; continue; }
|
||||
const m = u8[i + 1];
|
||||
if (m >= 0xc0 && m <= 0xcf && m !== 0xc4 && m !== 0xc8 && m !== 0xcc) {
|
||||
return { h: (u8[i + 5] << 8) | u8[i + 6], w: (u8[i + 7] << 8) | u8[i + 8] };
|
||||
}
|
||||
const len = (u8[i + 2] << 8) | u8[i + 3];
|
||||
if (!len) return null;
|
||||
i += 2 + len;
|
||||
}
|
||||
return null;
|
||||
} catch { return null; }
|
||||
}
|
||||
|
||||
/** หมุน/พลิกพิกเซลด้วย canvas */
|
||||
export async function transformImage(blob, rotateDeg = 0, mirror = false) {
|
||||
const bmp = await createImageBitmap(blob, { imageOrientation: "none" });
|
||||
const swap = Math.abs(rotateDeg) % 180 === 90;
|
||||
const w = swap ? bmp.height : bmp.width;
|
||||
const h = swap ? bmp.width : bmp.height;
|
||||
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
const ctx = canvas.getContext("2d");
|
||||
ctx.translate(w / 2, h / 2);
|
||||
ctx.rotate((rotateDeg * Math.PI) / 180);
|
||||
if (mirror) ctx.scale(-1, 1);
|
||||
ctx.drawImage(bmp, -bmp.width / 2, -bmp.height / 2);
|
||||
bmp.close?.();
|
||||
|
||||
const out = await new Promise((res) => canvas.toBlob(res, "image/jpeg", JPEG_QUALITY));
|
||||
return { blob: out || blob, width: w, height: h, rotated: rotateDeg !== 0 || mirror };
|
||||
}
|
||||
|
||||
async function makeThumb(blob) {
|
||||
try {
|
||||
const bmp = await createImageBitmap(blob, { imageOrientation: "none" });
|
||||
const scale = Math.min(1, THUMB_MAX / Math.max(bmp.width, bmp.height));
|
||||
const w = Math.max(1, Math.round(bmp.width * scale));
|
||||
const h = Math.max(1, Math.round(bmp.height * scale));
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
canvas.getContext("2d").drawImage(bmp, 0, 0, w, h);
|
||||
bmp.close?.();
|
||||
return await new Promise((res) => canvas.toBlob(res, "image/jpeg", THUMB_QUALITY));
|
||||
} catch { return blob; }
|
||||
}
|
||||
|
||||
/**
|
||||
* ปรับภาพให้ตั้งตรง
|
||||
* - exifOrientation: ค่าจาก readExif() (ถ้ามี)
|
||||
* - mirrorFront: true = กล้องหน้า → พลิกซ้าย-ขวาให้เหมือนพรีวิว (ค่าเริ่มต้น false)
|
||||
* คืน { blob, width, height, rotation, mirrored, source }
|
||||
*/
|
||||
export async function autoOrient({ blob, exifOrientation = 1, width, height, mirrorFront = false, facing = "environment" }) {
|
||||
const tag = ORIENTATION_MATRIX[exifOrientation] ? exifOrientation : 1;
|
||||
const plan = ORIENTATION_MATRIX[tag];
|
||||
|
||||
// กล้องหน้า: พรีวิวถูก mirror แต่ไฟล์ดิบไม่ mirror → พลิกให้ตรงกับที่เห็น
|
||||
const mirror = plan.mirror || (mirrorFront && facing === "user");
|
||||
const rotate = plan.rotate;
|
||||
|
||||
if (!rotate && !mirror) {
|
||||
return { blob, width: width || 0, height: height || 0, rotation: 0, mirrored: false, source: "none" };
|
||||
}
|
||||
|
||||
// เบราว์เซอร์หมุนตาม EXIF ให้เองหรือไม่ (Chrome/Android = ใช่) — ตรวจครั้งเดียวแล้ว cache
|
||||
if (await browserAppliesExif()) {
|
||||
const probe = await createImageBitmap(blob);
|
||||
const pw = probe.width, ph = probe.height;
|
||||
probe.close?.();
|
||||
const baked = await bakeToJpeg(blob);
|
||||
if (mirror) {
|
||||
const flipped = await transformImage(baked, 0, true);
|
||||
return { ...flipped, width: pw, height: ph, rotation: 0, mirrored: true, source: `browser:${tag}+mirror` };
|
||||
}
|
||||
return { blob: baked, width: pw, height: ph, rotation: 0, mirrored: false, source: `browser:${tag}` };
|
||||
}
|
||||
|
||||
// เบราว์เซอร์ไม่สนใจ EXIF → หมุนพิกเซลเองตามตาราง
|
||||
const out = await transformImage(blob, rotate, mirror);
|
||||
return {
|
||||
...out,
|
||||
rotation: rotate,
|
||||
mirrored: mirror,
|
||||
source: `exif:${tag}${mirrorFront && facing === "user" ? "+front" : ""}`,
|
||||
};
|
||||
}
|
||||
|
||||
let _exifSupport = null;
|
||||
/** ทดสอบว่า createImageBitmap หมุนตาม EXIF ให้หรือไม่ (cache ผลไว้) */
|
||||
async function browserAppliesExif() {
|
||||
if (_exifSupport !== null) return _exifSupport;
|
||||
try {
|
||||
const px = window.piexif;
|
||||
if (!px) { _exifSupport = true; return true; }
|
||||
const c = document.createElement("canvas");
|
||||
c.width = 40; c.height = 20;
|
||||
c.getContext("2d").fillRect(0, 0, 40, 20);
|
||||
const plain = await new Promise((r) => c.toBlob(r, "image/jpeg", 0.9));
|
||||
const durl = await blobToDataURL(plain);
|
||||
const raw = px.load(durl);
|
||||
raw["0th"][274] = 6;
|
||||
const tagged = dataURLToBlob(px.insert(px.dump(raw), durl));
|
||||
const bmp = await createImageBitmap(tagged);
|
||||
_exifSupport = bmp.width === 20 && bmp.height === 40;
|
||||
bmp.close?.();
|
||||
} catch { _exifSupport = true; }
|
||||
return _exifSupport;
|
||||
}
|
||||
|
||||
/** วาดภาพตามที่เบราว์เซอร์แสดง (bake) แล้วคืน JPEG ที่ไม่มี EXIF */
|
||||
async function bakeToJpeg(blob) {
|
||||
const bmp = await createImageBitmap(blob);
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = bmp.width;
|
||||
canvas.height = bmp.height;
|
||||
canvas.getContext("2d").drawImage(bmp, 0, 0);
|
||||
bmp.close?.();
|
||||
const out = await new Promise((res) => canvas.toBlob(res, "image/jpeg", JPEG_QUALITY));
|
||||
return out || blob;
|
||||
}
|
||||
|
||||
/** ครอปกลางภาพตามอัตราส่วน (4:3 = 1.333, 3:4 = 0.75) */
|
||||
export async function cropToRatio(blob, ratio) {
|
||||
try {
|
||||
const bmp = await createImageBitmap(blob, { imageOrientation: "none" });
|
||||
const w = bmp.width, h = bmp.height;
|
||||
const src = w / h;
|
||||
let sw = w, sh = h, sx = 0, sy = 0;
|
||||
if (src > ratio + 0.002) { sw = Math.round(h * ratio); sx = Math.round((w - sw) / 2); }
|
||||
else if (src < ratio - 0.002) { sh = Math.round(w / ratio); sy = Math.round((h - sh) / 2); }
|
||||
if (sw === w && sh === h) { bmp.close?.(); return { blob, width: w, height: h }; }
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = sw; canvas.height = sh;
|
||||
canvas.getContext("2d").drawImage(bmp, sx, sy, sw, sh, 0, 0, sw, sh);
|
||||
bmp.close?.();
|
||||
const out = await new Promise((res) => canvas.toBlob(res, "image/jpeg", JPEG_QUALITY));
|
||||
return { blob: out || blob, width: sw, height: sh };
|
||||
} catch { return { blob, width: 0, height: 0 }; }
|
||||
}
|
||||
|
||||
/** "4:3" → 1.333 */
|
||||
export function ratioValue(label) {
|
||||
const m = /^(\d+)\s*[:x/]\s*(\d+)$/.exec(String(label || ""));
|
||||
if (!m) return 4 / 3;
|
||||
const a = Number(m[1]), b = Number(m[2]);
|
||||
return b ? a / b : 4 / 3;
|
||||
}
|
||||
|
||||
/** หมุนภาพตามองศา (ใช้กับปุ่มหมุนในชีตรูป) และสร้าง thumb ใหม่ */
|
||||
export async function rotateBlob(blob, deg) {
|
||||
const out = await transformImage(blob, deg, false);
|
||||
const thumb = await makeThumb(out.blob);
|
||||
return { ...out, thumb };
|
||||
}
|
||||
|
||||
/** อ่าน orientation จาก blob แล้วคืนค่าตัวเลข 1-8 */
|
||||
export async function detectOrientation(blob) {
|
||||
try {
|
||||
const buf = await blob.arrayBuffer();
|
||||
return readOrientationTag(new Uint8Array(buf));
|
||||
} catch { return 1; }
|
||||
}
|
||||
|
||||
export { makeThumb as makeThumbFromBlob };
|
||||
@@ -64,9 +64,12 @@ export function cameraShell() {
|
||||
return `
|
||||
<div id="camera-view">
|
||||
<div class="stage">
|
||||
<video id="video" autoplay playsinline muted></video>
|
||||
<div class="grid-lines" id="grid-lines"></div>
|
||||
<div class="frame ratio-43" id="cam-frame">
|
||||
<video id="video" autoplay playsinline muted></video>
|
||||
<div class="grid-lines" id="grid-lines"></div>
|
||||
</div>
|
||||
<div class="cam-top">
|
||||
<button class="cam-chip ratio-chip" type="button" id="chip-ratio" data-action="toggle-ratio" aria-label="สลับอัตราส่วนภาพ 4:3 / 3:4">4:3</button>
|
||||
<button class="cam-chip" type="button" data-action="toggle-grid" aria-label="เส้นแบ่ง 3 ส่วน">${ICON.grid}</button>
|
||||
<button class="cam-chip" type="button" id="chip-torch" data-action="toggle-torch" aria-pressed="false" aria-label="ไฟแฟลช" hidden>${ICON.torch}</button>
|
||||
<button class="cam-chip" type="button" data-action="switch-camera" aria-label="สลับกล้องหน้า/หลัง">${ICON.flip}</button>
|
||||
@@ -106,7 +109,7 @@ export function hero(kind, { title, text = "", steps = [], action = null, note =
|
||||
</div>`;
|
||||
}
|
||||
|
||||
export function syncCameraControls({ torchAvailable, torchOn, zoomRange, zoomValue, gridOn, count, thumbUrl, ready }) {
|
||||
export function syncCameraControls({ torchAvailable, torchOn, zoomRange, zoomValue, gridOn, count, thumbUrl, ready, ratio }) {
|
||||
const chip = document.getElementById("chip-torch");
|
||||
if (chip) {
|
||||
chip.hidden = !torchAvailable;
|
||||
@@ -134,6 +137,15 @@ export function syncCameraControls({ torchAvailable, torchOn, zoomRange, zoomVal
|
||||
}
|
||||
}
|
||||
|
||||
const frame = document.getElementById("cam-frame");
|
||||
const ratioChip = document.getElementById("chip-ratio");
|
||||
if (frame) {
|
||||
const portrait = ratio === "3:4";
|
||||
frame.classList.toggle("ratio-43", !portrait);
|
||||
frame.classList.toggle("ratio-34", portrait);
|
||||
}
|
||||
if (ratioChip) ratioChip.textContent = ratio || "4:3";
|
||||
|
||||
const grid = document.getElementById("grid-lines");
|
||||
if (grid) grid.classList.toggle("on", !!gridOn);
|
||||
const cnt = document.getElementById("shot-count");
|
||||
@@ -147,9 +159,12 @@ export function syncCameraControls({ torchAvailable, torchOn, zoomRange, zoomVal
|
||||
// ── Folders ──
|
||||
export function renderFolders({ folders, counts, activeId, storage }) {
|
||||
const total = counts.reduce((a, b) => a + b, 0);
|
||||
let html = `<div class="section-head">
|
||||
let html = `<div class="folder-view"><div class="section-head">
|
||||
<div><h2>โฟลเดอร์</h2><div class="sub">${folders.length} โฟลเดอร์ · ${total} รูป</div></div>
|
||||
<button class="btn btn-primary" type="button" data-action="new-folder">+ โฟลเดอร์ใหม่</button>
|
||||
<div class="head-btns">
|
||||
<button class="btn btn-ghost" type="button" data-action="csv-sheet">CSV</button>
|
||||
<button class="btn btn-primary" type="button" data-action="new-folder">+ โฟลเดอร์ใหม่</button>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
if (!folders.length) {
|
||||
@@ -173,11 +188,17 @@ export function renderFolders({ folders, counts, activeId, storage }) {
|
||||
html += `</div>`;
|
||||
}
|
||||
|
||||
html += `<div class="folder-bulk">
|
||||
<button class="btn btn-ghost btn-block" type="button" data-action="zip-all">${ICON.zip} ZIP ทุกโฟลเดอร์ (${total} รูป)</button>
|
||||
</div>`;
|
||||
|
||||
html += `<div class="storage-line">
|
||||
พื้นที่เก็บในเครื่อง${storage ? ` · ใช้ ${fmtBytes(storage.usage)} จาก ${fmtBytes(storage.quota)}` : ""}
|
||||
<br><button class="btn btn-ghost" type="button" style="min-height:34px;height:34px;font-size:11px;margin-top:8px" data-action="diagnostics">ข้อมูลอุปกรณ์และกล้อง</button>
|
||||
<button class="btn btn-ghost" type="button" style="min-height:34px;height:34px;font-size:11px;margin-top:8px;margin-left:6px" data-action="show-qr">QR ลิงก์ทดสอบ</button>
|
||||
</div>`;
|
||||
|
||||
html += `</div>`;
|
||||
return html;
|
||||
}
|
||||
|
||||
@@ -205,9 +226,8 @@ export function renderGallery({ folder, images, thumbUrl }) {
|
||||
html += `</div>`;
|
||||
|
||||
html += `<div class="action-bar">
|
||||
<button class="btn btn-ghost" type="button" data-action="zip-download">${ICON.zip} ZIP (${images.length})</button>
|
||||
<button class="btn btn-primary" type="button" data-action="zip-share">${ICON.share} แชร์ ZIP</button>
|
||||
</div>`;
|
||||
<button class="btn btn-primary btn-block" type="button" data-action="zip-download">${ICON.zip} ZIP โฟลเดอร์นี้ (${images.length} รูป)</button>
|
||||
</div></div>`;
|
||||
return html;
|
||||
}
|
||||
|
||||
@@ -234,6 +254,12 @@ export function photoSheet({ record, url, folderName }) {
|
||||
}
|
||||
if (m.exif?.orientation) rows.push(["Orientation", String(m.exif.orientation)]);
|
||||
if (m.exif?.dateTimeOriginal) rows.push(["EXIF DateTimeOriginal", m.exif.dateTimeOriginal]);
|
||||
if (m.exif?.software) rows.push(["Software", m.exif.software]);
|
||||
if (m.exif?.gps?.dateStamp) {
|
||||
const t = Array.isArray(m.exif.gps.timeStamp) ? m.exif.gps.timeStamp.map((x) => String(Math.round(x)).padStart(2, "0")).join(":") : "";
|
||||
rows.push(["GPS date/time", `${m.exif.gps.dateStamp}${t ? " " + t : ""}`]);
|
||||
}
|
||||
if (m.exif?.uniqueId) rows.push(["ImageUniqueID", m.exif.uniqueId.slice(0, 16) + "…"]);
|
||||
|
||||
const rowsHtml = rows
|
||||
.map(([k, v]) => `<div class="row"><span class="k">${esc(k)}</span><span class="v">${esc(v)}</span></div>`)
|
||||
@@ -244,7 +270,18 @@ export function photoSheet({ record, url, folderName }) {
|
||||
<div class="hint">${esc(humanDateTime(record.createdAt))}</div>
|
||||
<img class="preview" src="${url}" alt="">
|
||||
<div class="meta-table">${rowsHtml}</div>
|
||||
<div class="hint" style="margin-top:10px;margin-bottom:0">ข้อมูลทั้งหมดฝังอยู่ในไฟล์ JPEG (EXIF) แล้ว — ติดไปกับรูปตอนแชร์/ดาวน์โหลด ไม่มีไฟล์แยก</div>
|
||||
<div class="sheet-actions" style="margin-top:14px">
|
||||
<button class="btn btn-ghost" type="button" data-action="rotate-photo" data-id="${esc(record.id)}" data-dir="-90" aria-label="หมุนซ้าย 90 องศา">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12a10 10 0 1 0 3-7"/><path d="M2 3v6h6"/></svg>
|
||||
ซ้าย
|
||||
</button>
|
||||
<button class="btn btn-ghost" type="button" data-action="rotate-photo" data-id="${esc(record.id)}" data-dir="90" aria-label="หมุนขวา 90 องศา">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M22 12a10 10 0 1 1-3-7"/><path d="M22 3v6h-6"/></svg>
|
||||
ขวา
|
||||
</button>
|
||||
</div>
|
||||
<div class="sheet-actions" style="margin-top:8px">
|
||||
<button class="btn btn-ghost" type="button" data-action="close-sheet">ปิด</button>
|
||||
<button class="btn btn-primary" type="button" data-action="share-photo" data-id="${esc(record.id)}">${ICON.share} แชร์รูปนี้</button>
|
||||
</div>
|
||||
@@ -265,9 +302,9 @@ export function folderSheet(mode, { id = "", name = "", suggested = "", count =
|
||||
}
|
||||
const isNew = mode === "new";
|
||||
return `<h3>${isNew ? "โฟลเดอร์ใหม่" : "เปลี่ยนชื่อโฟลเดอร์"}</h3>
|
||||
<div class="hint">ชื่อเริ่มต้นอิงวันที่ไทย (พ.ศ.) ของวันนี้ — แก้ไขได้</div>
|
||||
<div class="hint">ชื่อเริ่มต้น = Site + ตัวอักษรถัดไป + ปี.เดือน.วัน.ชั่วโมง.นาที (แก้ได้)</div>
|
||||
<input id="folder-name-input" type="text" inputmode="text" autocomplete="off"
|
||||
value="${esc(isNew ? suggested : name)}" placeholder="Site A 2569-10-24">
|
||||
value="${esc(isNew ? suggested : name)}" placeholder="Site a 2569.10.25.21.45">
|
||||
${isNew ? `<div class="hint" style="margin-top:-6px">ถ้าชื่อซ้ำ ระบบจะเติม (2) ให้อัตโนมัติ</div>` : ""}
|
||||
<div class="sheet-actions">
|
||||
<button class="btn btn-ghost" type="button" data-action="close-sheet">ยกเลิก</button>
|
||||
@@ -290,6 +327,64 @@ export function qrSheet(url) {
|
||||
</div></div>`;
|
||||
}
|
||||
|
||||
// ── CSV import ──────────────────────────────────────────────
|
||||
export function csvSheet() {
|
||||
return `<h3>นำเข้าโฟลเดอร์จาก CSV</h3>
|
||||
<div class="hint">สร้างทีละหลายโฟลเดอร์ในครั้งเดียว — ชื่อที่ได้จะใช้กฎ Site + ตัวอักษร + ปี.เดือน.วัน.ชั่วโมง.นาที</div>
|
||||
<div class="meta-table">
|
||||
<div class="row"><span class="k">site</span><span class="v">คำนำหน้า เช่น Site (เว้นว่าง = Site)</span></div>
|
||||
<div class="row"><span class="k">letter</span><span class="v">a…z, aa… (เว้นว่าง = ไล่ต่ออัตโนมัติ)</span></div>
|
||||
<div class="row"><span class="k">datetime</span><span class="v">2569.10.25.21.45</span></div>
|
||||
<div class="row"><span class="k">name</span><span class="v">ชื่อเต็ม (ถ้าใส่ จะทับชื่อที่ประกอบ)</span></div>
|
||||
</div>
|
||||
<div class="hint" style="margin-top:12px">ตัวอย่างแถว<br><code>Site,a,2569.10.25.21.45,</code><br><code>Site,b,2569.10.25.22.10,</code></div>
|
||||
<div class="sheet-actions" style="margin-top:12px">
|
||||
<a class="btn btn-ghost" href="templates/folders-template.csv" download="folders-template.csv">ไฟล์เปล่า</a>
|
||||
<button class="btn btn-primary" type="button" data-action="pick-csv">เลือกไฟล์ CSV</button>
|
||||
</div>
|
||||
<div class="sheet-actions" style="margin-top:8px">
|
||||
<button class="btn btn-ghost btn-block" type="button" data-action="close-sheet">ปิด</button>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
export function importResultSheet({ created, skipped, errors = [], total }) {
|
||||
const list = errors.length
|
||||
? `<div class="notice" style="margin:12px 0 0">
|
||||
<b>ข้าม ${skipped} แถว</b>
|
||||
<ol>${errors.slice(0, 12).map((e) => `<li>แถว ${e.row}: ${esc(e.reason)}</li>`).join("")}</ol>
|
||||
${errors.length > 12 ? `<div style="margin-top:6px">…อีก ${errors.length - 12} แถว</div>` : ""}
|
||||
</div>`
|
||||
: "";
|
||||
return `<h3>สร้างโฟลเดอร์แล้ว ${created} รายการ</h3>
|
||||
<div class="hint">อ่าน ${total} แถว · สำเร็จ ${created} · ข้าม ${skipped}</div>
|
||||
${list}
|
||||
<div class="sheet-actions" style="margin-top:14px">
|
||||
<button class="btn btn-primary btn-block" type="button" data-action="close-sheet">เรียบร้อย</button>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// ── พร้อมแชร์ (หลังสร้าง ZIP) ────────────────────────────────
|
||||
export function shareReadySheet({ name, size, canShare, reason }) {
|
||||
const status = canShare ? "พร้อมส่งเข้าแอปอื่น" : "เบราว์เซอร์นี้ไม่รองรับการแชร์ไฟล์";
|
||||
const note = canShare
|
||||
? "แตะปุ่มด้านล่างเพื่อเปิด share sheet ของ Samsung"
|
||||
: "บันทึกไฟล์แล้วแชร์ผ่าน Files/My Files หรือเปิดด้วย Chrome";
|
||||
return `<h3>ZIP พร้อมแล้ว</h3>
|
||||
<div class="meta-table">
|
||||
<div class="row"><span class="k">ไฟล์</span><span class="v">${esc(name)}</span></div>
|
||||
<div class="row"><span class="k">ขนาด</span><span class="v">${esc(fmtBytes(size))}</span></div>
|
||||
<div class="row"><span class="k">การแชร์</span><span class="v">${esc(status)}</span></div>
|
||||
</div>
|
||||
<div class="hint" style="margin-top:12px">${esc(note)}${reason ? " · " + esc(reason) : ""}</div>
|
||||
<div class="sheet-actions">
|
||||
<button class="btn btn-ghost" type="button" data-action="save-zip">บันทึกไฟล์</button>
|
||||
<button class="btn btn-primary" type="button" data-action="share-zip-now" ${canShare ? "" : "disabled"}>แชร์ไปแอปอื่น</button>
|
||||
</div>
|
||||
<div class="sheet-actions" style="margin-top:8px">
|
||||
<button class="btn btn-ghost btn-block" type="button" data-action="close-sheet">ปิด</button>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// ── Diagnostics ──
|
||||
export function diagnosticsSheet(rows) {
|
||||
const body = rows
|
||||
|
||||
@@ -0,0 +1,682 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="th">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#F2F3F5" media="(prefers-color-scheme: light)">
|
||||
<meta name="theme-color" content="#000000" media="(prefers-color-scheme: dark)">
|
||||
<meta name="color-scheme" content="light dark">
|
||||
<title>คู่มือใช้งาน CamCat · CamCat Manual</title>
|
||||
<style>
|
||||
/* ── Tokens (ชุดเดียวกับแอป) ─────────────────────────────── */
|
||||
:root{
|
||||
--bg:#F2F3F5; --bg-2:#E8EAED; --card:#FFFFFF; --text:#101114; --text-2:#5C6169;
|
||||
--line:rgba(16,17,20,.09); --accent:#0A72DE; --accent-text:#0E5FB8; --accent-soft:#E4EFFC;
|
||||
--warn-bg:#FFF4D6; --warn-line:#E9C46A; --danger-bg:#FCE8E6; --danger:#B3261E;
|
||||
--ok-bg:#E4F6EC; --ok:#0F6B3F;
|
||||
--radius:26px; --radius-s:14px; --pad:20px;
|
||||
--shadow:0 1px 2px rgba(16,17,20,.05),0 8px 24px rgba(16,17,20,.06);
|
||||
--mono:ui-monospace,"SF Mono",Menlo,Consolas,"Cascadia Mono",monospace;
|
||||
}
|
||||
@media (prefers-color-scheme: dark){
|
||||
:root:not([data-theme="light"]){
|
||||
--bg:#000; --bg-2:#101114; --card:#1B1B1D; --text:#F2F3F5; --text-2:#A9AEB6;
|
||||
--line:rgba(255,255,255,.12); --accent:#4E9DFF; --accent-text:#6FB3FF; --accent-soft:#16304D;
|
||||
--warn-bg:#3A2F12; --warn-line:#8A6D1E; --danger-bg:#3A1A18; --danger:#FF8A80;
|
||||
--ok-bg:#10291D; --ok:#6FE0A8; --shadow:none;
|
||||
}
|
||||
}
|
||||
:root[data-theme="dark"]{
|
||||
--bg:#000; --bg-2:#101114; --card:#1B1B1D; --text:#F2F3F5; --text-2:#A9AEB6;
|
||||
--line:rgba(255,255,255,.12); --accent:#4E9DFF; --accent-text:#6FB3FF; --accent-soft:#16304D;
|
||||
--warn-bg:#3A2F12; --warn-line:#8A6D1E; --danger-bg:#3A1A18; --danger:#FF8A80;
|
||||
--ok-bg:#10291D; --ok:#6FE0A8; --shadow:none;
|
||||
}
|
||||
|
||||
*{margin:0;padding:0;box-sizing:border-box}
|
||||
html{scroll-behavior:smooth;scroll-padding-top:88px}
|
||||
body{
|
||||
background:var(--bg); color:var(--text);
|
||||
font-family:"SamsungOneUI","Noto Sans Thai","IBM Plex Sans Thai",-apple-system,
|
||||
BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
|
||||
font-size:16px; line-height:1.7; -webkit-font-smoothing:antialiased;
|
||||
padding-bottom:64px;
|
||||
}
|
||||
a{color:var(--accent-text);text-decoration:none}
|
||||
a:hover{text-decoration:underline}
|
||||
code,kbd,samp{font-family:var(--mono);font-size:.92em}
|
||||
code{background:var(--bg-2);padding:.12em .42em;border-radius:6px;border:1px solid var(--line)}
|
||||
|
||||
/* ── Header ── */
|
||||
.top{
|
||||
position:sticky;top:0;z-index:20;background:color-mix(in srgb,var(--bg) 86%,transparent);
|
||||
backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);
|
||||
border-bottom:1px solid var(--line);
|
||||
}
|
||||
.top-in{max-width:1180px;margin:0 auto;display:flex;align-items:center;gap:12px;padding:14px var(--pad)}
|
||||
.brand{display:flex;align-items:center;gap:10px;min-width:0}
|
||||
.logo{width:38px;height:38px;border-radius:13px;background:var(--accent-soft);color:var(--accent-text);
|
||||
display:grid;place-items:center;flex:0 0 auto}
|
||||
.logo svg{width:22px;height:22px}
|
||||
.brand h1{font-size:18px;line-height:1.25;letter-spacing:-.2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||
.brand .ver{font-size:12px;color:var(--text-2);font-weight:400;display:block}
|
||||
.top-actions{margin-left:auto;display:flex;gap:8px;flex:0 0 auto}
|
||||
.icon-btn{width:44px;height:44px;border-radius:50%;border:0;background:var(--card);color:var(--text-2);
|
||||
display:grid;place-items:center;cursor:pointer;box-shadow:var(--shadow)}
|
||||
.icon-btn:hover{color:var(--text)}
|
||||
.icon-btn svg{width:21px;height:21px}
|
||||
.icon-btn:focus-visible,a:focus-visible,summary:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:8px}
|
||||
|
||||
/* ── Layout ── */
|
||||
.wrap{max-width:1180px;margin:0 auto;padding:28px var(--pad);display:grid;grid-template-columns:248px minmax(0,1fr);gap:36px}
|
||||
@media(max-width:900px){.wrap{grid-template-columns:1fr;gap:18px;padding-top:18px}}
|
||||
|
||||
/* ── TOC ── */
|
||||
.toc{position:sticky;top:84px;align-self:start;font-size:14px;max-height:calc(100vh - 110px);overflow:auto}
|
||||
.toc h2{font-size:12px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-2);margin-bottom:10px;font-weight:600}
|
||||
.toc ol{list-style:none;display:flex;flex-direction:column;gap:2px}
|
||||
.toc a{display:block;padding:7px 10px;border-radius:10px;color:var(--text-2)}
|
||||
.toc a:hover{background:var(--bg-2);text-decoration:none;color:var(--text)}
|
||||
.toc a.active{background:var(--accent-soft);color:var(--accent-text);font-weight:600}
|
||||
@media(max-width:900px){
|
||||
.toc{position:static;max-height:none;background:var(--card);border-radius:var(--radius-s);
|
||||
padding:10px 12px;box-shadow:var(--shadow);font-size:14px}
|
||||
.toc h2{margin-bottom:6px}
|
||||
.toc ol{display:grid;grid-template-columns:1fr 1fr;gap:6px}
|
||||
.toc a{display:flex;align-items:center;min-height:44px;padding:8px 12px;background:var(--bg-2);
|
||||
border-radius:12px;font-size:13px;line-height:1.35}
|
||||
.toc a.active{background:var(--accent-soft)}
|
||||
}
|
||||
|
||||
/* ── Content ── */
|
||||
main{min-width:0}
|
||||
.lead{background:var(--card);border-radius:var(--radius);padding:22px 24px;box-shadow:var(--shadow);margin-bottom:24px}
|
||||
.lead h2{font-size:21px;letter-spacing:-.3px;margin-bottom:6px}
|
||||
.lead p{color:var(--text-2);font-size:15px}
|
||||
.lead .chips{display:flex;flex-wrap:wrap;gap:8px;margin-top:14px}
|
||||
.chip{font-size:12.5px;background:var(--bg-2);color:var(--text-2);border:1px solid var(--line);
|
||||
border-radius:999px;padding:4px 12px;font-weight:500}
|
||||
|
||||
section{background:var(--card);border-radius:var(--radius);padding:24px;box-shadow:var(--shadow);margin-bottom:20px}
|
||||
section>h2{font-size:20px;letter-spacing:-.3px;display:flex;align-items:center;gap:10px;margin-bottom:4px}
|
||||
section>h2 .num{flex:0 0 auto;width:28px;height:28px;border-radius:9px;background:var(--accent-soft);color:var(--accent-text);
|
||||
font-size:13px;font-weight:700;display:grid;place-items:center}
|
||||
section>.sub{color:var(--text-2);font-size:14px;margin-bottom:16px}
|
||||
h3{font-size:16.5px;margin:22px 0 8px}
|
||||
h3:first-of-type{margin-top:12px}
|
||||
p{margin:8px 0}
|
||||
ul,ol{margin:8px 0 8px 22px}
|
||||
li{margin:4px 0}
|
||||
li::marker{color:var(--accent-text)}
|
||||
|
||||
/* ── Table ── */
|
||||
.tbl{width:100%;border-collapse:collapse;margin:12px 0;font-size:14.5px}
|
||||
.tbl th,.tbl td{text-align:left;padding:10px 12px;border-bottom:1px solid var(--line);vertical-align:top}
|
||||
.tbl th{font-size:12.5px;text-transform:uppercase;letter-spacing:.04em;color:var(--text-2);font-weight:600;
|
||||
background:var(--bg-2);border-radius:0}
|
||||
.tbl tr:last-child td{border-bottom:0}
|
||||
.tbl code{white-space:nowrap}
|
||||
.scroll-x{overflow-x:auto;-webkit-overflow-scrolling:touch}
|
||||
|
||||
/* ── Callouts ── */
|
||||
.note,.warn,.ok{border-radius:var(--radius-s);padding:14px 16px;margin:14px 0;font-size:14.5px;border:1px solid transparent}
|
||||
.note{background:var(--accent-soft);color:var(--text);border-color:color-mix(in srgb,var(--accent) 30%,transparent)}
|
||||
.warn{background:var(--warn-bg);border-color:var(--warn-line);color:var(--text)}
|
||||
.ok{background:var(--ok-bg);border-color:color-mix(in srgb,var(--ok) 40%,transparent);color:var(--text)}
|
||||
.note b,.warn b,.ok b{display:block;margin-bottom:4px;font-size:14px}
|
||||
|
||||
/* ── Steps ── */
|
||||
.steps{list-style:none;margin:12px 0;display:flex;flex-direction:column;gap:10px;counter-reset:s}
|
||||
.steps li{position:relative;padding-left:38px;counter-increment:s;margin:0}
|
||||
.steps li::before{content:counter(s);position:absolute;left:0;top:1px;width:26px;height:26px;border-radius:50%;
|
||||
background:var(--accent-soft);color:var(--accent-text);font-size:13px;font-weight:700;display:grid;place-items:center}
|
||||
|
||||
/* ── Code block ── */
|
||||
pre{background:var(--bg-2);border:1px solid var(--line);border-radius:var(--radius-s);padding:14px 16px;
|
||||
overflow-x:auto;font-family:var(--mono);font-size:13.5px;line-height:1.6;margin:12px 0}
|
||||
pre code{background:none;border:0;padding:0}
|
||||
|
||||
/* ── UI mock chips (แสดงชื่อปุ่มในแอป) ── */
|
||||
.ui{display:inline-flex;align-items:center;gap:6px;font-size:13px;font-weight:600;border-radius:999px;
|
||||
padding:3px 11px;border:1px solid var(--line);background:var(--bg-2);color:var(--text);white-space:nowrap}
|
||||
.ui.primary{background:var(--accent);color:#fff;border-color:transparent}
|
||||
.ui.round{width:26px;height:26px;justify-content:center;padding:0;border-radius:50%}
|
||||
.ui svg{width:14px;height:14px}
|
||||
|
||||
/* ── Cards grid (quick actions) ── */
|
||||
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:12px;margin:14px 0}
|
||||
.mini{background:var(--bg-2);border-radius:var(--radius-s);padding:14px 16px}
|
||||
.mini b{display:block;font-size:14.5px;margin-bottom:2px}
|
||||
.mini span{font-size:13px;color:var(--text-2)}
|
||||
|
||||
/* ── Footer ── */
|
||||
footer{max-width:1180px;margin:0 auto;padding:8px var(--pad) 0;color:var(--text-2);font-size:12.5px;text-align:center}
|
||||
|
||||
/* ── Print ── */
|
||||
@media print{
|
||||
:root{--bg:#fff;--card:#fff;--text:#000;--text-2:#333;--bg-2:#f3f3f3;--shadow:none}
|
||||
body{padding:0;font-size:11.5pt}
|
||||
.top,.toc,.no-print{display:none !important}
|
||||
.wrap{display:block;padding:0;max-width:none}
|
||||
section{box-shadow:none;border:1px solid #ddd;break-inside:avoid;margin-bottom:10px;padding:12px 14px}
|
||||
h2,h3{break-after:avoid}
|
||||
a{color:#000;text-decoration:none}
|
||||
pre{white-space:pre-wrap}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="top">
|
||||
<div class="top-in">
|
||||
<div class="brand">
|
||||
<span class="logo" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg>
|
||||
</span>
|
||||
<h1>คู่มือใช้งาน CamCat
|
||||
<span class="ver">ถ่ายรูปแยกโฟลเดอร์ · Web App (PWA) · v2.2.2</span>
|
||||
</h1>
|
||||
</div>
|
||||
<div class="top-actions">
|
||||
<button class="icon-btn" id="themeBtn" type="button" aria-label="สลับธีมสว่าง/มืด"></button>
|
||||
<button class="icon-btn no-print" onclick="window.print()" type="button" aria-label="พิมพ์คู่มือ">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9V3h12v6"/><rect x="3" y="9" width="18" height="8" rx="2"/><path d="M6 17h12v4H6z"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="wrap">
|
||||
<nav class="toc" aria-label="สารบัญ">
|
||||
<h2>สารบัญ</h2>
|
||||
<ol>
|
||||
<li><a href="#start">1. เริ่มใช้งาน</a></li>
|
||||
<li><a href="#perm">2. สิทธิ์กล้อง/ตำแหน่ง</a></li>
|
||||
<li><a href="#camera">3. หน้าถ่ายรูป</a></li>
|
||||
<li><a href="#folder">4. โฟลเดอร์ & กฎชื่อ</a></li>
|
||||
<li><a href="#csv">5. นำเข้าจาก CSV</a></li>
|
||||
<li><a href="#gallery">6. แกลเลอรี & Metadata</a></li>
|
||||
<li><a href="#zip">7. ZIP และการแชร์</a></li>
|
||||
<li><a href="#exif">8. EXIF ในไฟล์</a></li>
|
||||
<li><a href="#settings">9. ธีม & ข้อมูลเครื่อง</a></li>
|
||||
<li><a href="#faq">10. ปัญหาที่พบบ่อย</a></li>
|
||||
<li><a href="#limits">11. ข้อจำกัด</a></li>
|
||||
<li><a href="#admin">12. สำหรับผู้ดูแล</a></li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<main>
|
||||
<div class="lead">
|
||||
<h2>แอปนี้ทำอะไร</h2>
|
||||
<p>CamCat คือเว็บแอป (ติดตั้งเป็น PWA ได้) สำหรับถ่ายรูปหน้างานบนมือถือ จัดกลุ่มเป็นโฟลเดอร์ตามไซต์
|
||||
พร้อมฝังข้อมูล EXIF/GPS ลงในไฟล์รูป รวบทั้งโฟลเดอร์เป็น ZIP แล้วดาวน์โหลดเก็บไว้</p>
|
||||
<div class="chips">
|
||||
<span class="chip">ถ่ายรูป + ไฟแฟลช + ซูม</span>
|
||||
<span class="chip">โฟลเดอร์ Site a 2569.10.25.21.45</span>
|
||||
<span class="chip">นำเข้า CSV</span>
|
||||
<span class="chip">EXIF + GPS ในไฟล์</span>
|
||||
<span class="chip">ZIP ทั้งโฟลเดอร์</span>
|
||||
<span class="chip">ใช้ได้แม้ออฟไลน์</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 1 ─────────────────────────────────────────────── -->
|
||||
<section id="start">
|
||||
<h2><span class="num">1</span>เริ่มใช้งาน</h2>
|
||||
<div class="sub">เปิดผ่าน HTTPS เท่านั้น — กล้องจะทำงานเฉพาะหน้าเว็บที่ปลอดภัย</div>
|
||||
|
||||
<h3>เปิดแอป</h3>
|
||||
<ol class="steps">
|
||||
<li>สแกน QR ที่ผู้ดูแลส่งให้ ด้วยกล้องมือถือ → เปิดลิงก์ใน <b>Chrome</b></li>
|
||||
<li>หรือพิมพ์ URL ที่ขึ้นต้นด้วย <code>https://</code> ใน Chrome</li>
|
||||
<li>อนุญาต <b>กล้อง</b> และ <b>ตำแหน่ง</b> (ตำแหน่งใช้ฝัง GPS ลงรูป)</li>
|
||||
<li>ติดตั้งเป็นแอป: เมนู ⋮ → <b>เพิ่มไปที่หน้าจอหลัก</b> / <b>ติดตั้งแอป</b></li>
|
||||
</ol>
|
||||
|
||||
<div class="note">
|
||||
<b>ทำไมต้อง HTTPS</b>
|
||||
เบราว์เซอร์อนุญาต <code>getUserMedia</code> เฉพาะ secure context ถ้าเปิดด้วย
|
||||
<code>http://192.168.x.x</code> จะไม่เห็นกล้องและมักไม่ขึ้น error ที่ชัดเจน
|
||||
</div>
|
||||
|
||||
<div class="grid">
|
||||
<div class="mini"><b>ติดตั้งแล้ว</b><span>เปิดจากไอคอนบนหน้าจอหลัก ทำงานเต็มจอ (standalone)</span></div>
|
||||
<div class="mini"><b>ออฟไลน์</b><span>เปิดแอปและถ่ายรูปได้ ข้อมูลเก็บในเครื่อง (IndexedDB)</span></div>
|
||||
<div class="mini"><b>ข้อมูลอยู่เครื่อง</b><span>ไม่มีเซิร์ฟเวอร์เก็บรูป ลบแอป/ล้างข้อมูล = รูปหาย</span></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 2 ─────────────────────────────────────────────── -->
|
||||
<section id="perm">
|
||||
<h2><span class="num">2</span>สิทธิ์กล้องและตำแหน่ง</h2>
|
||||
<div class="sub">ครั้งแรกจะมีหน้าต่างขออนุญาต — ต้องกด “อนุญาต”</div>
|
||||
|
||||
<table class="tbl">
|
||||
<thead><tr><th>สิทธิ์</th><th>ใช้ทำอะไร</th><th>ถ้าไม่อนุญาต</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>กล้อง (Camera)</td><td>แสดงภาพสดและถ่ายรูป</td><td>ขึ้นหน้าแจ้งพร้อมปุ่ม “ลองใหม่”</td></tr>
|
||||
<tr><td>ตำแหน่ง (Location)</td><td>ฝังพิกัด GPS + ความแม่นยำลง EXIF</td><td>ถ่ายได้ปกติ แต่รูปไม่มี GPS</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>ถ้าเผลอกดบล็อกไปแล้ว (Samsung / Android)</h3>
|
||||
<ol class="steps">
|
||||
<li>การตั้งค่า → แอป → Chrome → สิทธิ์ → <b>กล้อง</b> → อนุญาต</li>
|
||||
<li>ทำแบบเดียวกันกับ <b>ตำแหน่ง</b></li>
|
||||
<li>หรือกดไอคอนกุญแจ/แถบที่อยู่ → <b>การอนุญาตของไซต์</b> → รีเซ็ตสิทธิ์</li>
|
||||
<li>กลับมาเปิดแอปใหม่ แล้วกด “ลองใหม่”</li>
|
||||
</ol>
|
||||
|
||||
<div class="warn">
|
||||
<b>ถ้ากล้องไม่ขึ้นเลยทั้งที่อนุญาตแล้ว</b>
|
||||
มักเปิดผ่าน <code>http://</code> อยู่ — ตรวจว่า URL ขึ้นต้นด้วย <code>https://</code>
|
||||
หรือเปิดในแท็บที่ไม่ได้ติดตั้งจากลิงก์ tunnel ที่หมดอายุ
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 3 ─────────────────────────────────────────────── -->
|
||||
<section id="camera">
|
||||
<h2><span class="num">3</span>หน้าถ่ายรูป</h2>
|
||||
<div class="sub">แถบเมนูล่างมี 3 แท็บ: กล้อง · โฟลเดอร์ · รูปภาพ</div>
|
||||
|
||||
<table class="tbl">
|
||||
<thead><tr><th>ปุ่ม</th><th>ทำอะไร</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><span class="ui round"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M12 5v14M5 12h14"/></svg></span> มุมขวาบน</td><td>สร้างโฟลเดอร์ใหม่ทันที (ชื่อตามกฎ) — ใช้บ่อยตอนเริ่มงาน</td></tr>
|
||||
<tr><td><span class="ui round"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 13.4A9 9 0 1 1 10.6 3a7 7 0 0 0 10.4 10.4z"/></svg></span></td><td>สลับธีม ตามระบบ → สว่าง → มืด</td></tr>
|
||||
<tr><td><span class="ui round"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/></svg></span></td><td>ข้อมูลอุปกรณ์และกล้อง (diagnostics)</td></tr>
|
||||
<tr><td>วงกลมขาวตรงกลาง</td><td>ชัตเตอร์ — ถ่ายและบันทึกเข้าช่องโฟลเดอร์ที่ใช้งาน</td></tr>
|
||||
<tr><td>ปุ่มเพิ่ม/ลดเสียง</td><td>ชัตเตอร์สำรอง (เฉพาะ APK) — กดค้าง/กดรัวมี debounce 0.6 วิ</td></tr>
|
||||
<tr><td><span class="ui round"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 2h6l-1 7h4l-7 13 1-8H8z"/></svg></span></td><td>ไฟแฟลช (torch) — แสดงเฉพาะเครื่องที่รองรับ (S23 รองรับ)</td></tr>
|
||||
<tr><td><span class="ui round"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M23 4v6h-6M1 20v-6h6"/><path d="M3.5 9a9 9 0 0 1 14.9-3.4L23 10M1 14l4.6 4.4A9 9 0 0 0 20.5 15"/></svg></span></td><td>สลับกล้องหน้า/หลัง</td></tr>
|
||||
<tr><td><span class="ui round"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v18M15 3v18M3 9h18M3 15h18"/></svg></span></td><td>เปิด/ปิดเส้นแบ่ง 3 ส่วน</td></tr>
|
||||
<tr><td><span class="ui">1× 2× 3×</span></td><td>ซูมแบบแตะ (แสดงตามความสามารถของกล้อง)</td></tr>
|
||||
<tr><td><span class="ui">4:3</span> / <span class="ui">3:4</span></td><td>สลับอัตราส่วนภาพ — กรอบพรีวิวเปลี่ยนตาม และไฟล์ที่ได้ถูกครอปตามจริง</td></tr>
|
||||
<tr><td>รูปย่อซ้ายล่าง</td><td>เปิดรูปล่าสุดที่เพิ่งถ่าย</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>ระหว่างถ่าย</h3>
|
||||
<ul>
|
||||
<li>รูปถูกบันทึกทันทีที่กดชัตเตอร์ พร้อม EXIF และ GPS (ถ้าอนุญาต)</li>
|
||||
<li>เลขมุมขวาล่างบอกจำนวนรูปในโฟลเดอร์ปัจจุบัน</li>
|
||||
<li>ออกจากแท็บกล้อง กล้องจะหยุดเพื่อประหยัดแบต — กลับมาเปิดใหม่ให้อัตโนมัติ</li>
|
||||
<li>สลับแอประหว่างถ่าย กล้องจะถูกปิดและเปิดใหม่เมื่อกลับมา</li>
|
||||
</ul>
|
||||
|
||||
<div class="ok">
|
||||
<b>ภาพตั้งตรงอัตโนมัติ</b>
|
||||
หลังถ่าย ระบบอ่าน EXIF Orientation ของไฟล์ → หมุนพิกเซลให้ตั้งตรง → เขียน Orientation = 1 กลับ
|
||||
(ถ้าเบราว์เซอร์หมุนให้อยู่แล้วจะ bake ทับ ไม่หมุนซ้ำ) · ถ้าภาพยังเอียง ใช้ปุ่มหมุนซ้าย/ขวาในชีตรูป
|
||||
</div>
|
||||
|
||||
<div class="ok">
|
||||
<b>แนวนอนไม่พัง</b>
|
||||
เวอร์ชัน APK ล็อกแนวตั้ง (screenOrientation=portrait) — ถือมือถือแนวนอน UI ไม่หมุนตาม
|
||||
ยังกดชัตเตอร์ถ่ายได้ปกติ · บนเว็บ เบราว์เซอร์อาจหมุนจอเองแต่ปุ่มยังอยู่ในกรอบ
|
||||
</div>
|
||||
|
||||
<div class="note">
|
||||
<b>ได้ความละเอียดเท่าไร</b>
|
||||
แอปจะใช้ <code>ImageCapture.takePhoto()</code> เพื่อดึงภาพนิ่งความละเอียดสูงสุดที่เบราว์เซอร์อนุญาต
|
||||
ถ้าเครื่องนั้นไม่รองรับ จะถ่ายเฟรมจากวิดีโอแทน (ความละเอียดเท่าสตรีม เช่น 1920×1080)
|
||||
ดูค่าจริงได้ที่ปุ่ม <span class="ui round"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/></svg></span> → “สตรีมกล้อง”
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 4 ─────────────────────────────────────────────── -->
|
||||
<section id="folder">
|
||||
<h2><span class="num">4</span>โฟลเดอร์และกฎการตั้งชื่อ</h2>
|
||||
<div class="sub">ชื่อเริ่มต้นสร้างให้อัตโนมัติ ไม่ต้องพิมพ์</div>
|
||||
|
||||
<p><b>รูปแบบ:</b> <code>Site <ตัวอักษร> <ปี พ.ศ.>.<เดือน>.<วัน>.<ชั่วโมง>.<นาที></code></p>
|
||||
<pre><code>Site a 2569.10.25.21.45
|
||||
Site b 2569.10.25.22.10
|
||||
Site c 2569.10.26.08.00</code></pre>
|
||||
|
||||
<h3>ตัวอักษรไล่อย่างไร</h3>
|
||||
<p>นับแบบคอลัมน์ Excel: <code>a … z</code> → <code>aa, ab … az</code> → <code>ba … bz</code> → <code>ca …</code> ไปเรื่อย ๆ
|
||||
ระบบเลือกตัวอักษรถัดไปจากชื่อโฟลเดอร์ที่มีอยู่จริง จึงไม่ชนกันแม้ลบหรือเปลี่ยนชื่อโฟลเดอร์เก่า</p>
|
||||
|
||||
<table class="tbl">
|
||||
<thead><tr><th>ปุ่มในหน้าโฟลเดอร์</th><th>ผล</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><span class="ui primary">+ โฟลเดอร์ใหม่</span></td><td>เปิดชีตให้ตรวจ/แก้ชื่อก่อนสร้าง</td></tr>
|
||||
<tr><td><span class="ui">CSV</span></td><td>สร้างหลายโฟลเดอร์พร้อมกันจากไฟล์ (ดูข้อ 5)</td></tr>
|
||||
<tr><td><span class="ui primary">ZIP ทุกโฟลเดอร์</span></td><td>รวมทุกโฟลเดอร์เป็น ZIP เดียว แล้วดาวน์โหลด (แต่ละโฟลเดอร์เป็นโฟลเดอร์ย่อย)</td></tr>
|
||||
<tr><td><span class="ui round"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z"/></svg></span></td><td>เปลี่ยนชื่อโฟลเดอร์ (เปลี่ยนได้ตลอด ไม่กระทบรูป)</td></tr>
|
||||
<tr><td><span class="ui round"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6"/><path d="M10 11v6M14 11v6"/></svg></span></td><td>ลบโฟลเดอร์ <b>และรูปทั้งหมดในนั้น</b> — กู้คืนไม่ได้</td></tr>
|
||||
<tr><td>แตะที่แถวโฟลเดอร์</td><td>ตั้งเป็นโฟลเดอร์ที่ใช้งาน (pill ใต้ชื่อแอปจะเปลี่ยน)</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="warn">
|
||||
<b>ลบโฟลเดอร์ = ลบรูปในเครื่องถาวร</b>
|
||||
ถ้ารูปสำคัญ ให้ ZIP ออกมาก่อนทุกครั้ง
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 5 ─────────────────────────────────────────────── -->
|
||||
<section id="csv">
|
||||
<h2><span class="num">5</span>นำเข้าโฟลเดอร์จาก CSV</h2>
|
||||
<div class="sub">สร้างทีละหลายโฟลเดอร์จากไฟล์ Excel / Google Sheets ที่บันทึกเป็น CSV</div>
|
||||
|
||||
<h3>หัวตาราง 4 คอลัมน์</h3>
|
||||
<div class="scroll-x">
|
||||
<table class="tbl">
|
||||
<thead><tr><th>คอลัมน์</th><th>ค่า</th><th>เว้นว่างได้</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><code>site</code></td><td>คำนำหน้า เช่น <code>Site</code></td><td>ได้ → ใช้ <code>Site</code></td></tr>
|
||||
<tr><td><code>letter</code></td><td><code>a</code>…<code>z</code>, <code>aa</code>…</td><td>ได้ → ไล่ต่ออัตโนมัติ</td></tr>
|
||||
<tr><td><code>datetime</code></td><td><code>2569.10.25.21.45</code> (รับ <code>2026-10-25 21:45</code> ด้วย)</td><td>ไม่ได้ ถ้าไม่มี <code>name</code></td></tr>
|
||||
<tr><td><code>name</code></td><td>ชื่อเต็ม — ถ้าใส่ จะใช้แทนชื่อที่ประกอบขึ้น</td><td>ได้</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<h3>ตัวอย่างไฟล์</h3>
|
||||
<pre><code>site,letter,datetime,name
|
||||
Site,a,2569.10.25.21.45,
|
||||
Site,b,2569.10.25.22.10,
|
||||
Site,,2569.10.26.08.00,หน้างานพิเศษ</code></pre>
|
||||
|
||||
<p>ไฟล์เปล่า (หัวตารางเท่านั้น) ดาวน์โหลดได้ในชีต CSV → ปุ่ม <span class="ui">ไฟล์เปล่า</span>
|
||||
หรือที่ <code>templates/folders-template.csv</code></p>
|
||||
|
||||
<h3>วิธีใช้</h3>
|
||||
<ol class="steps">
|
||||
<li>เปิดแท็บ <b>โฟลเดอร์</b> → กด <span class="ui">CSV</span></li>
|
||||
<li>กด <span class="ui primary">เลือกไฟล์ CSV</span> แล้วเลือกไฟล์จากเครื่อง</li>
|
||||
<li>ระบบสร้างโฟลเดอร์ทีละรายการ แล้วสรุปผลให้ดู</li>
|
||||
</ol>
|
||||
|
||||
<div class="note">
|
||||
<b>แถวที่ถูกข้าม</b>
|
||||
ระบบจะบอกเลขแถวและเหตุผล เช่น <code>แถว 5: datetime "bad" อ่านไม่ได้</code> หรือ
|
||||
<code>ชื่อซ้ำ: Site g 2569.10.26.11.00</code> — แถวที่ถูกต้องยังถูกสร้างตามปกติ
|
||||
</div>
|
||||
|
||||
<h3>ข้อควรระวังของไฟล์</h3>
|
||||
<ul>
|
||||
<li>บันทึกเป็น <b>CSV UTF-8</b> (Excel: “CSV UTF-8 (comma delimited)”) เพื่อให้ชื่อไทยไม่เพี้ยน</li>
|
||||
<li>คั่นด้วย comma หรือ semicolon หรือ tab ก็ได้ (ระบบตรวจให้อัตโนมัติ)</li>
|
||||
<li>ชื่อที่มี comma ให้ครอบด้วย <code>"…"</code></li>
|
||||
<li>ปีที่กรอกเป็น ค.ศ. ระบบแปลงเป็น พ.ศ. ให้ (บวก 543)</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<!-- 6 ─────────────────────────────────────────────── -->
|
||||
<section id="gallery">
|
||||
<h2><span class="num">6</span>แกลเลอรีและ Metadata</h2>
|
||||
<div class="sub">ดูรูป ตรวจข้อมูลที่ฝังไว้ และลบรูปที่ไม่ใช้</div>
|
||||
|
||||
<p>แท็บ <b>รูปภาพ</b> แสดงรูปของโฟลเดอร์ที่ใช้งานเป็นตาราง 3 คอลัมน์ (4 คอลัมน์บนจอใหญ่)
|
||||
แตะรูปเพื่อเปิดชีตรายละเอียด</p>
|
||||
|
||||
<h3>ข้อมูลที่แสดงในชีตรูป</h3>
|
||||
<table class="tbl">
|
||||
<thead><tr><th>รายการ</th><th>ที่มา</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>ชื่อไฟล์ / ขนาด / ความละเอียด (MP)</td><td>ไฟล์จริง</td></tr>
|
||||
<tr><td>ถ่ายเมื่อ (วันที่ไทย พ.ศ.)</td><td>เวลาที่บันทึก</td></tr>
|
||||
<tr><td>อุปกรณ์ / กล้องหน้า-หลัง / ที่มาไฟล์</td><td>ตรวจจากเบราว์เซอร์ + วิธีจับภาพ</td></tr>
|
||||
<tr><td>พิกัด GPS ± ความแม่นยำ (เมตร)</td><td>geolocation ตอนกดชัตเตอร์</td></tr>
|
||||
<tr><td>รุ่นใน EXIF / Orientation / DateTimeOriginal / Software</td><td>อ่านกลับจากไฟล์</td></tr>
|
||||
<tr><td>ImageUniqueID</td><td>รหัสเฉพาะของรูป</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>ปุ่มในชีตรูป</h3>
|
||||
<ul>
|
||||
<li><span class="ui">แชร์รูปนี้</span> — ส่ง “ไฟล์รูปเดี่ยว” เข้า share sheet ของเครื่อง</li>
|
||||
<li><span class="ui">ลบรูปนี้</span> — ลบเฉพาะรูปนี้ในเครื่อง (ถาวร)</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<!-- 7 ─────────────────────────────────────────────── -->
|
||||
<section id="zip">
|
||||
<h2><span class="num">7</span>ZIP และการแชร์</h2>
|
||||
<div class="sub">รวมทุกรูปในโฟลเดอร์เป็นไฟล์เดียว แล้วดาวน์โหลดลงเครื่อง</div>
|
||||
|
||||
<p>ในแท็บ <b>รูปภาพ</b> มีปุ่มเดียวที่แถบล่าง: <span class="ui primary">ZIP ทั้งโฟลเดอร์ (N รูป)</span></p>
|
||||
|
||||
<h3>สิ่งที่ได้ในไฟล์ ZIP</h3>
|
||||
<pre><code>Site b 2569.10.25.23.10.zip
|
||||
└── Site b 2569.10.25.23.10/ ← โฟลเดอร์จริงในไฟล์ zip
|
||||
├── Site_b_2569.10.25.23.10_0001.jpg
|
||||
└── Site_b_2569.10.25.23.10_0002.jpg</code></pre>
|
||||
<ul>
|
||||
<li>แตกไฟล์แล้วได้ <b>โฟลเดอร์</b> ไม่ใช่รูปกระจัดกระจายที่ root</li>
|
||||
<li>ไฟล์ JPEG ทุกรูปอยู่ข้างใน (ไม่บีบอัดซ้ำ เพื่อความเร็วบนมือถือ)</li>
|
||||
<li><b>ไม่มีไฟล์ JSON แยก</b> — metadata อยู่ใน EXIF ของแต่ละรูป (ดูข้อ 8)</li>
|
||||
</ul>
|
||||
|
||||
<h3>ZIP ทุกโฟลเดอร์ (ครั้งเดียว)</h3>
|
||||
<p>หน้าโฟลเดอร์ → ปุ่ม <span class="ui primary">ZIP ทุกโฟลเดอร์ (N รูป)</span> ได้ไฟล์เดียวชื่อ
|
||||
<code>CamCat-all-YYYYMMDD-HHMM.zip</code> โดยแต่ละโฟลเดอร์เป็นโฟลเดอร์ย่อยของตัวเอง:</p>
|
||||
<pre><code>CamCat-all-20261029-0002.zip
|
||||
├── Site a 2569.10.25.21.45/
|
||||
│ └── Site_a_2569.10.25.21.45_0001.jpg
|
||||
└── Site b 2569.10.25.23.10/
|
||||
└── Site_b_2569.10.25.23.10_0001.jpg</code></pre>
|
||||
|
||||
<h3>ปลายทางของไฟล์</h3>
|
||||
<ul>
|
||||
<li>Chrome จะบันทึกที่โฟลเดอร์ <b>Download</b> ของเครื่อง (ดูได้ใน My Files → Downloads)</li>
|
||||
<li>ชื่อไฟล์ zip ใช้ชื่อโฟลเดอร์ เช่น <code>Site a 2569.10.25.22.15.zip</code></li>
|
||||
<li>ต้องมีพื้นที่ว่างพอ — ขนาด zip ≈ ผลรวมขนาดรูป (บวกไม่กี่ KB)</li>
|
||||
</ul>
|
||||
|
||||
<div class="note">
|
||||
<b>ปุ่มแชร์ ZIP ถูกถอดออกแล้ว</b>
|
||||
ถ้าต้องการส่งเข้าแอปอื่น ให้ดาวน์โหลด ZIP แล้วแชร์จาก My Files
|
||||
ส่วนการส่งรูปเดี่ยวใช้ปุ่ม <span class="ui">แชร์รูปนี้</span> ในชีตรูปได้ทันที
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 8 ─────────────────────────────────────────────── -->
|
||||
<section id="exif">
|
||||
<h2><span class="num">8</span>EXIF ที่ฝังอยู่ในไฟล์</h2>
|
||||
<div class="sub">เปิดรูปด้วย Samsung Gallery / Google Photos / exiftool แล้วเห็นข้อมูลทันที</div>
|
||||
|
||||
<div class="scroll-x">
|
||||
<table class="tbl">
|
||||
<thead><tr><th>กลุ่ม (IFD)</th><th>แท็กที่เขียน</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>IFD0</td><td>ImageDescription (<code>CamCat · ชื่อโฟลเดอร์</code>), Make, Model, Artist, Orientation, X/YResolution + Unit, Software, DateTime</td></tr>
|
||||
<tr><td>Exif</td><td>ExifVersion 0232, DateTimeOriginal, DateTimeDigitized, ComponentsConfiguration, ColorSpace (sRGB), PixelXDimension, PixelYDimension, ExposureBias, ExposureMode/WhiteBalance/DigitalZoomRatio/Contrast/Saturation/Sharpness, ImageUniqueID</td></tr>
|
||||
<tr><td>GPS</td><td>GPSVersionID, Latitude/Longitude (องศา-ลิปดา-ฟิลิปดา), Altitude, GPSTimeStamp, GPSDateStamp, GPSProcessingMethod, GPSHPositioningError (± เมตร)</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="ok">
|
||||
<b>ชื่อโฟลเดอร์ภาษาไทย</b>
|
||||
แท็ก ASCII เก็บได้เฉพาะอักษรละติน ระบบจึงเก็บชื่อไทยไว้ใน <code>XPComment</code> / <code>XPKeywords</code>
|
||||
(UTF-16LE) ทำให้เปิดใน Windows Explorer หรือโปรแกรมที่อ่าน XP tags แล้วเห็นชื่อไทยครบ
|
||||
</div>
|
||||
|
||||
<div class="warn">
|
||||
<b>สิ่งที่เบราว์เซอร์ทำให้ไม่ได้</b>
|
||||
ไม่สามารถสร้าง MakerNote เฉพาะของ Samsung (โหมดถ่าย, เลนส์, ค่าเฉพาะเครื่อง) หรือไฟล์ HEIF ได้
|
||||
เพราะเป็นข้อมูล proprietary ของแอปกล้องเครื่อง — EXIF มาตรฐานตามตารางข้างบนครบถ้วน
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 9 ─────────────────────────────────────────────── -->
|
||||
<section id="settings">
|
||||
<h2><span class="num">9</span>ธีม & ข้อมูลเครื่อง</h2>
|
||||
|
||||
<h3>ธีม</h3>
|
||||
<p>ปุ่ม ☾/☀ บนหัวแอป วน 3 สถานะ: <b>ตามระบบ</b> → <b>สว่าง</b> → <b>มืด</b> ค่าถูกจำไว้ในเครื่อง</p>
|
||||
|
||||
<h3>ข้อมูลอุปกรณ์และกล้อง</h3>
|
||||
<p>กด <span class="ui round"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/></svg></span> บนหัวแอป หรือปุ่มในหน้าโฟลเดอร์ จะเห็น:</p>
|
||||
<ul>
|
||||
<li>รุ่นเครื่อง (เช่น <code>Galaxy S23 (SM-S911B)</code>) และเวอร์ชัน Android/Chrome</li>
|
||||
<li>ขนาดหน้าจอ CSS, DPR, visualViewport, โหมดติดตั้ง PWA</li>
|
||||
<li>สถานะ HTTPS (จำเป็นต่อกล้อง), URL ปัจจุบัน</li>
|
||||
<li>ความละเอียดสตรีมกล้อง, กล้องหน้า/หลัง, การรองรับ ImageCapture</li>
|
||||
<li>ไฟแฟลช, ช่วงซูม, โหมดโฟกัส, การรองรับแชร์ไฟล์</li>
|
||||
<li>พื้นที่เก็บข้อมูลที่ใช้ไป และจำนวนโฟลเดอร์/รูป</li>
|
||||
</ul>
|
||||
|
||||
<h3>QR ลิงก์ทดสอบ</h3>
|
||||
<p>หน้าโฟลเดอร์ → <span class="ui">QR ลิงก์ทดสอบ</span> แสดง QR ของ URL ที่กำลังเปิดอยู่
|
||||
ใช้ส่งต่อให้เครื่องอื่น หรือเช็กว่าลิงก์เป็น <code>https://</code> จริง</p>
|
||||
</section>
|
||||
|
||||
<!-- 10 ────────────────────────────────────────────── -->
|
||||
<section id="faq">
|
||||
<h2><span class="num">10</span>ปัญหาที่พบบ่อย</h2>
|
||||
|
||||
<h3>เปิดแอปแล้วไม่เห็นภาพกล้อง</h3>
|
||||
<ul>
|
||||
<li>URL ต้องเป็น <code>https://</code> (ไม่ใช่ <code>http://</code> และไม่ใช่ IP ใน LAN ตรง ๆ)</li>
|
||||
<li>ตรวจสิทธิ์กล้องของ Chrome ตามข้อ 2</li>
|
||||
<li>ปิดแอปอื่นที่ใช้กล้องอยู่ (กล้อง/วิดีโอคอล) แล้วกด “ลองใหม่”</li>
|
||||
</ul>
|
||||
|
||||
<h3>ไม่มี GPS ในรูป</h3>
|
||||
<ul>
|
||||
<li>ยังไม่ได้อนุญาตสิทธิ์ตำแหน่ง → อนุญาตแล้วถ่ายใหม่</li>
|
||||
<li>อยู่ในที่ร่ม/ในอาคาร GPS อาจไม่ล็อกภายใน 7 วินาที (แอปจะบันทึกรูปโดยไม่มีพิกัด)</li>
|
||||
</ul>
|
||||
|
||||
<h3>รูปที่ถ่ายได้ความละเอียดไม่สูง</h3>
|
||||
<ul>
|
||||
<li>เครื่องนั้นไม่รองรับ <code>ImageCapture</code> → ระบบใช้เฟรมวิดีโอ (ดู “ที่มาไฟล์” ในชีตรูป)</li>
|
||||
<li>ตรวจค่าจริงได้ที่หน้า diagnostics → “สตรีมกล้อง”</li>
|
||||
</ul>
|
||||
|
||||
<h3>กด ZIP แล้วไม่มีไฟล์</h3>
|
||||
<ul>
|
||||
<li>ดูที่ Chrome → ดาวน์โหลด (หรือ My Files → Downloads)</li>
|
||||
<li>ถ้าพื้นที่เครื่องเต็ม การดาวน์โหลดจะล้มเหลว — ลบรูปเก่าหรือย้าย ZIP ออกก่อน</li>
|
||||
</ul>
|
||||
|
||||
<h3>ลิงก์ที่ได้มาเปิดไม่ได้</h3>
|
||||
<ul>
|
||||
<li>ลิงก์ tunnel เป็นลิงก์ชั่วคราว ถ้าเซิร์ฟเวอร์/เครื่องแม่ข่ายปิด จะใช้ไม่ได้ทันที — ขอ QR ใหม่</li>
|
||||
</ul>
|
||||
|
||||
<h3>ข้อมูลในแอปหายหลังล้างข้อมูลเบราว์เซอร์</h3>
|
||||
<ul>
|
||||
<li>รูปเก็บใน IndexedDB ของเบราว์เซอร์ การ “ล้างข้อมูลไซต์” หรือถอนการติดตั้งจะลบทั้งหมด → ZIP เก็บไว้เป็นประจำ</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<!-- 11 ────────────────────────────────────────────── -->
|
||||
<section id="limits">
|
||||
<h2><span class="num">11</span>ข้อจำกัดที่ควรรู้</h2>
|
||||
<ul>
|
||||
<li><b>ต้องมี HTTPS</b> — ไม่มีทางเลี่ยงได้บนมือถือ (ยกเว้นตั้งค่า chrome://flags เป็นกรณียกเว้น)</li>
|
||||
<li><b>EXIF เฉพาะมาตรฐาน</b> — ไม่มี MakerNote ของ Samsung/HEIF</li>
|
||||
<li><b>ข้อมูลอยู่ในเครื่องนี้เท่านั้น</b> — ไม่ซิงก์ข้ามเครื่อง ไม่มี backup อัตโนมัติ</li>
|
||||
<li><b>พื้นที่เก็บ</b> — เบราว์เซอร์ให้พื้นที่ตาม quota ของเครื่อง (ดูในหน้า diagnostics)</li>
|
||||
<li><b>การแชร์ไฟล์</b> — ใช้ได้เฉพาะเบราว์เซอร์ที่รองรับ Web Share ระดับไฟล์ (Chrome Android รองรับ)</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<!-- 12 ────────────────────────────────────────────── -->
|
||||
<section id="admin">
|
||||
<h2><span class="num">12</span>สำหรับผู้ดูแลระบบ</h2>
|
||||
|
||||
<h3>รันบนเครื่องทดสอบ</h3>
|
||||
<pre><code>cd app
|
||||
python -m http.server 8099 --bind 0.0.0.0
|
||||
|
||||
# กล้องต้องใช้ HTTPS → เปิด tunnel
|
||||
cloudflared tunnel --url http://127.0.0.1:8099 --no-autoupdate</code></pre>
|
||||
|
||||
<h3>ไฟล์สำคัญ</h3>
|
||||
<div class="scroll-x">
|
||||
<table class="tbl">
|
||||
<thead><tr><th>ไฟล์</th><th>หน้าที่</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><code>index.html</code></td><td>โครงหน้า + header/nav</td></tr>
|
||||
<tr><td><code>css/app.css</code></td><td>Design tokens + คอมโพเนนต์ (light/dark)</td></tr>
|
||||
<tr><td><code>js/main.js</code></td><td>state, event, ธีม, diagnostics</td></tr>
|
||||
<tr><td><code>js/camera.js</code></td><td>getUserMedia, ImageCapture, torch, zoom</td></tr>
|
||||
<tr><td><code>js/exif.js</code></td><td>เขียน/อ่าน EXIF (piexifjs)</td></tr>
|
||||
<tr><td><code>js/csv.js</code></td><td>parse CSV + วางแผนสร้างโฟลเดอร์</td></tr>
|
||||
<tr><td><code>js/naming.js</code></td><td>กฎชื่อ Site + ตัวอักษร + เวลาไทย</td></tr>
|
||||
<tr><td><code>js/archive.js</code></td><td>สร้าง ZIP + ดาวน์โหลด/แชร์</td></tr>
|
||||
<tr><td><code>sw.js</code> / <code>manifest.json</code></td><td>PWA cache + ข้อมูลติดตั้ง</td></tr>
|
||||
<tr><td><code>templates/folders-template.csv</code></td><td>ไฟล์ CSV เปล่า (หัวตาราง)</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="note">
|
||||
<b>อัปเดตแอปแล้วไม่เห็นของใหม่</b>
|
||||
Service Worker จะถือไฟล์เวอร์ชันเก่า — เพิ่มเลข <code>CACHE</code> ใน <code>sw.js</code>
|
||||
แล้วปิด/เปิดแท็บใหม่ หรือล้างข้อมูลไซต์
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer>CamCat v2.2.2 · เอกสารหน้าเดียว (standalone) · พิมพ์/บันทึกเป็น PDF ได้จากปุ่มพิมพ์มุมขวาบน</footer>
|
||||
|
||||
<script>
|
||||
// ธีม: ตามระบบ → สว่าง → มืด
|
||||
(function(){
|
||||
const KEY = "camcat.manual.theme";
|
||||
// file:// หรือโหมดที่บล็อก storage → ไม่ให้สคริปต์ล้ม
|
||||
const store = {
|
||||
get: function (k) { try { return localStorage.getItem(k); } catch (e) { return null; } },
|
||||
set: function (k, v) { try { localStorage.setItem(k, v); } catch (e) {} }
|
||||
};
|
||||
const btn = document.getElementById("themeBtn");
|
||||
const SUN = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4.2"/><path d="M12 2v2.2M12 19.8V22M2 12h2.2M19.8 12H22M4.9 4.9l1.6 1.6M17.5 17.5l1.6 1.6M19.1 4.9l-1.6 1.6M6.5 17.5l-1.6 1.6"/></svg>';
|
||||
const MOON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 13.4A9 9 0 1 1 10.6 3a7 7 0 0 0 10.4 10.4z"/></svg>';
|
||||
|
||||
function dark(){
|
||||
const f = document.documentElement.dataset.theme;
|
||||
if (f === "dark") return true;
|
||||
if (f === "light") return false;
|
||||
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
}
|
||||
function paint(){
|
||||
btn.innerHTML = dark() ? SUN : MOON;
|
||||
btn.setAttribute("aria-label", dark() ? "เปลี่ยนเป็นธีมสว่าง" : "เปลี่ยนเป็นธีมมืด");
|
||||
}
|
||||
function apply(mode){
|
||||
if (mode === "light" || mode === "dark") document.documentElement.dataset.theme = mode;
|
||||
else document.documentElement.removeAttribute("data-theme");
|
||||
store.set(KEY, mode);
|
||||
paint();
|
||||
}
|
||||
apply(store.get(KEY) || "auto");
|
||||
btn.addEventListener("click", function(){
|
||||
const order = ["auto", "light", "dark"];
|
||||
const cur = store.get(KEY) || "auto";
|
||||
apply(order[(order.indexOf(cur) + 1) % order.length]);
|
||||
});
|
||||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function(){
|
||||
if ((store.get(KEY) || "auto") === "auto") paint();
|
||||
});
|
||||
})();
|
||||
|
||||
// TOC scrollspy
|
||||
(function(){
|
||||
const links = [...document.querySelectorAll(".toc a")];
|
||||
const map = new Map(links.map(a => [a.getAttribute("href").slice(1), a]));
|
||||
const secs = [...document.querySelectorAll("section[id]")];
|
||||
if (!("IntersectionObserver" in window) || !secs.length) return;
|
||||
const io = new IntersectionObserver((entries) => {
|
||||
entries.forEach((en) => {
|
||||
const a = map.get(en.target.id);
|
||||
if (!a) return;
|
||||
if (en.isIntersecting) {
|
||||
links.forEach(l => l.classList.remove("active"));
|
||||
a.classList.add("active");
|
||||
}
|
||||
});
|
||||
}, { rootMargin: "-30% 0px -60% 0px", threshold: 0 });
|
||||
secs.forEach(s => io.observe(s));
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,10 +1,11 @@
|
||||
// Service Worker — CamCat 2.0
|
||||
// กลยุทธ์: navigation = network-first (ได้เวอร์ชันใหม่ก่อน) · asset = stale-while-revalidate
|
||||
const CACHE = "camcat-v2.1.1";
|
||||
const CACHE = "camcat-v2.6.0";
|
||||
|
||||
const ASSETS = [
|
||||
"./",
|
||||
"./index.html",
|
||||
"./manual.html",
|
||||
"./manifest.json",
|
||||
"./css/app.css",
|
||||
"./js/config.js",
|
||||
@@ -14,11 +15,15 @@ const ASSETS = [
|
||||
"./js/device.js",
|
||||
"./js/camera.js",
|
||||
"./js/archive.js",
|
||||
"./js/csv.js",
|
||||
"./js/native.js",
|
||||
"./js/orient.js",
|
||||
"./js/ui.js",
|
||||
"./js/main.js",
|
||||
"./vendor/jszip.min.js",
|
||||
"./vendor/piexif.js",
|
||||
"./vendor/qrcode.min.js",
|
||||
"./templates/folders-template.csv",
|
||||
"./icon-192.png",
|
||||
"./icon-512.png",
|
||||
];
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
site,letter,datetime,name
|
||||
|
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"appId": "com.camcat.app",
|
||||
"appName": "CamCat",
|
||||
"webDir": "app",
|
||||
"bundledWebRuntime": false,
|
||||
"android": {
|
||||
"allowMixedContent": false,
|
||||
"webContentsDebuggingEnabled": true
|
||||
},
|
||||
"server": {
|
||||
"androidScheme": "https"
|
||||
},
|
||||
"plugins": {
|
||||
"SplashScreen": {
|
||||
"launchAutoHide": true,
|
||||
"backgroundColor": "#F2F3F5"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "camcat",
|
||||
"version": "2.3.0",
|
||||
"private": true,
|
||||
"description": "CamCat — field photo capture, folders, EXIF, ZIP",
|
||||
"scripts": {
|
||||
"cap:add": "cap add android",
|
||||
"cap:sync": "cap sync android",
|
||||
"apk": "cap sync android && cd android && gradlew.bat assembleDebug",
|
||||
"apk:release": "cap sync android && cd android && gradlew.bat assembleRelease"
|
||||
},
|
||||
"dependencies": {
|
||||
"@capacitor/android": "^6.2.0",
|
||||
"@capacitor/core": "^6.2.0",
|
||||
"@capacitor/filesystem": "^6.0.1",
|
||||
"@capacitor/share": "^6.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@capacitor/cli": "^6.2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# สร้าง APK (ต้องมี JDK 17 + Android SDK; node/npm มีอยู่แล้ว)
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
echo "== 1) ติดตั้ง dependencies =="
|
||||
npm install
|
||||
|
||||
if [ ! -d android ]; then
|
||||
echo "== 2) เพิ่ม platform android =="
|
||||
npx cap add android
|
||||
fi
|
||||
|
||||
echo "== 3) copy เว็บแอป (app/) เข้า android =="
|
||||
npx cap sync android
|
||||
|
||||
echo "== 4) build APK (debug) =="
|
||||
cd android
|
||||
if [ -f gradlew.bat ]; then ./gradlew.bat assembleDebug; else ./gradlew assembleDebug; fi
|
||||
|
||||
APK="app/build/outputs/apk/debug/app-debug.apk"
|
||||
echo
|
||||
echo "APK: android/$APK"
|
||||
ls -lh "$APK" || true
|
||||