feat(workshop): 채팅 중 찍은 카메라 사진(자동 첨부·📸)을 프로젝트 사진/ 폴더에 바로 저장 — 보관용은 1920px/0.9
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
95532d398e
commit
6669db0c61
2 files changed
+26
-6
No files matched your search
+10
-5
@@ -67,24 +67,29 @@
|
||||
window.cameraClose = closeCamera;
|
||||
window.cameraIsOn = function () { return !!stream; };
|
||||
|
||||
function captureBlob() {
|
||||
// hiRes: 파일로 보관할 때(작업실 사진 폴더)는 채팅 입력용 다운스케일보다 크게·높은 화질로 찍는다
|
||||
function captureBlob(hiRes) {
|
||||
var video = $('camera-video');
|
||||
if (!stream || !video || !video.videoWidth) return Promise.resolve(null);
|
||||
var w = video.videoWidth, h = video.videoHeight;
|
||||
var scale = Math.min(1, MAX_SIDE / Math.max(w, h));
|
||||
var scale = Math.min(1, (hiRes ? 1920 : MAX_SIDE) / Math.max(w, h));
|
||||
var cw = Math.round(w * scale), ch = Math.round(h * scale);
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = cw; canvas.height = ch;
|
||||
canvas.getContext('2d').drawImage(video, 0, 0, cw, ch);
|
||||
return new Promise(function (resolve) { canvas.toBlob(resolve, 'image/jpeg', JPEG_QUALITY); });
|
||||
return new Promise(function (resolve) { canvas.toBlob(resolve, 'image/jpeg', hiRes ? 0.9 : JPEG_QUALITY); });
|
||||
}
|
||||
|
||||
window.cameraCaptureBlob = function () { return captureBlob(); };
|
||||
window.cameraCaptureBlob = function (hiRes) { return captureBlob(hiRes); };
|
||||
|
||||
// 현재 프레임을 서버에 올리고 채팅용 마크다운을 돌려준다. 실패하면 '' (메시지는 그대로 전송된다).
|
||||
// 페이지가 window.cameraFrameSaver(blob) → 이미지 마크다운('' 이면 실패)을 정의하면 그쪽에 맡긴다
|
||||
// (작업실: 프로젝트 사진 폴더에 바로 저장). 없으면 기존처럼 임시 업로드.
|
||||
async function uploadFrame() {
|
||||
var blob = await captureBlob();
|
||||
var saver = typeof window.cameraFrameSaver === 'function' ? window.cameraFrameSaver : null;
|
||||
var blob = await captureBlob(!!saver);
|
||||
if (!blob) return '';
|
||||
if (saver) return await saver(blob, CAMERA_ALT);
|
||||
var form = new FormData();
|
||||
form.append('image', blob, 'camera-' + Date.now() + '.jpg');
|
||||
var res = await fetch('/api/upload/image', { method: 'POST', headers: authHdr(), body: form });
|
||||
|
||||
@@ -267,12 +267,27 @@ function attachPhoto(relPath){
|
||||
autoResize(inp);inp.focus();
|
||||
document.getElementById('attach-pop').classList.remove('open');
|
||||
}
|
||||
// 채팅 중 찍힌 카메라 프레임(자동 첨부·📸 촬영)은 임시 업로드 대신 이 프로젝트의 사진/ 폴더에 바로 저장한다.
|
||||
// camera.js가 이 함수를 쓴다 — 돌려주는 마크다운의 /api/files/ 경로가 곧 프로젝트 폴더의 파일이다.
|
||||
window.cameraFrameSaver=async function(blob,alt){
|
||||
const proj=currentProject();
|
||||
if(!proj)return '';
|
||||
const d=new Date(),p2=n=>String(n).padStart(2,'0');
|
||||
const name='camera-'+d.getFullYear()+p2(d.getMonth()+1)+p2(d.getDate())+'-'+p2(d.getHours())+p2(d.getMinutes())+p2(d.getSeconds())+'.jpg';
|
||||
const fd=new FormData();fd.append('file',blob,name);
|
||||
const r=await fetch('/api/workshop/upload?projectId='+encodeURIComponent(proj.id)+'&folder='+encodeURIComponent('사진'),{method:'POST',headers:authH(),body:fd});
|
||||
const j=await r.json().catch(()=>({}));
|
||||
if(!r.ok||!j.url)throw new Error(j.error||'사진 저장 실패');
|
||||
const pane=document.getElementById('pane-files');
|
||||
if(pane&&pane.classList.contains('active'))loadFiles();
|
||||
return '';
|
||||
};
|
||||
// 카메라 현재 화면을 이 프로젝트의 사진 폴더에 저장하고 채팅에 첨부한다 (수동 촬영 = 기록용).
|
||||
async function saveCameraShot(){
|
||||
const proj=currentProject();
|
||||
const pop=document.getElementById('attach-pop');
|
||||
if(!proj)return;
|
||||
const blob=await window.cameraCaptureBlob();
|
||||
const blob=await window.cameraCaptureBlob(true);
|
||||
if(!blob){pop.innerHTML='<div class="rb-empty">카메라 화면을 아직 읽을 수 없습니다.</div>';return;}
|
||||
pop.innerHTML='<div class="rb-empty">저장 중…</div>';
|
||||
try{
|
||||
|
||||
Reference in new issue
Block a user