feat(라이브): 결과 이미지에서 매출을 읽어 판매금액 칸에 채움
- 방송 창에서 이미지를 고르면 POST /live/broadcasts/read-sales 가 서버 Tesseract 로 이미지 위 절반의 첫 RM 금액(틱톡 LIVE 결과 화면 Attr. GMV)을 읽어 돌려줌(저장 안 함) - RM1.2K 같은 줄인 값·못 찾음은 칸을 두고 안내, 사람이 확인 후 저장 - Dockerfile: tesseract-ocr·tesseract-ocr-eng 설치 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+23
-2
@@ -27,16 +27,17 @@
|
||||
const hostSelect = form.querySelector('select[name="host_id"]');
|
||||
const fileInput = form.querySelector('input[type="file"]');
|
||||
|
||||
function say(text) {
|
||||
function say(text, info) {
|
||||
msg.textContent = text || "";
|
||||
msg.hidden = !text;
|
||||
msg.classList.toggle("is-info", !!info);
|
||||
}
|
||||
|
||||
async function post(url, body) {
|
||||
try {
|
||||
const res = await fetch(url, { method: "POST", body: body, headers: { Accept: "application/json" } });
|
||||
const data = await res.json().catch(function () { return {}; });
|
||||
return { ok: res.ok && data.ok !== false, message: data.message || data.detail || "HTTP " + res.status };
|
||||
return { ok: res.ok && data.ok !== false, message: data.message || data.detail || "HTTP " + res.status, data: data };
|
||||
} catch (_) {
|
||||
return { ok: false, message: tr("서버에 연결하지 못했습니다. 입력한 값은 그대로 있으니 다시 저장해 보세요.") };
|
||||
}
|
||||
@@ -128,6 +129,26 @@
|
||||
if (edit) { const row = JSON.parse(edit.dataset.edit); row.is_active = sw.checked; edit.dataset.edit = JSON.stringify(row); }
|
||||
});
|
||||
|
||||
// 결과 이미지를 고르면 서버가 글자 인식으로 매출(틱톡 LIVE 결과 화면의 첫 RM 금액)을 읽어 판매금액 칸에 채운다 — 저장은 사람이 확인 후
|
||||
const salesInput = form.elements.sales_amount;
|
||||
if (fileInput && salesInput) fileInput.addEventListener("change", async function () {
|
||||
const files = Array.from(fileInput.files);
|
||||
if (!files.length) return;
|
||||
const save = form.querySelector('button[type="submit"]');
|
||||
save.disabled = true;
|
||||
say(tr("이미지에서 매출을 읽는 중…"), true);
|
||||
let r = null;
|
||||
for (const f of files) { // 매출을 찾을 때까지 한 장씩
|
||||
const body = new FormData();
|
||||
body.set("image", f);
|
||||
r = await post("/live/broadcasts/read-sales", body);
|
||||
if (!r.ok || r.data.amount) break;
|
||||
}
|
||||
save.disabled = false;
|
||||
if (r.ok && r.data.amount) salesInput.value = r.data.amount;
|
||||
say(r.message, r.ok);
|
||||
});
|
||||
|
||||
form.addEventListener("submit", async function (e) {
|
||||
e.preventDefault();
|
||||
const save = form.querySelector('button[type="submit"]');
|
||||
|
||||
Reference in New Issue
Block a user