MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / downloadImage

Function downloadImage

src/composables/useScreenCapture.ts:51–78  ·  view source on GitHub ↗

* 保存图片到专用下载目录

(imageData: string)

Source from the content-addressed store, hash-verified

49 * 保存图片到专用下载目录
50 */
51 async function downloadImage(imageData: string) {
52 const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19)
53 const filename = `chatlab-screenshot-${timestamp}.png`
54
55 try {
56 const result = await useCacheService().saveToDownloads(filename, imageData)
57 if (result.success) {
58 toast.add({
59 title: '截图已保存',
60 description: `已保存到下载目录:${filename}`,
61 color: 'primary',
62 actions: [
63 {
64 label: '打开目录',
65 onClick: () => {
66 useCacheService().openDir('downloads')
67 },
68 },
69 ],
70 })
71 } else {
72 throw new Error(result.error)
73 }
74 } catch (error) {
75 console.error('保存图片失败:', error)
76 toast.fail('保存失败', { description: String(error) })
77 }
78 }
79
80 /**
81 * 显示截屏成功的 Toast

Callers 1

showSuccessToastFunction · 0.85

Calls 5

useCacheServiceFunction · 0.90
saveToDownloadsMethod · 0.65
openDirMethod · 0.65
errorMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected