filecache

This commit is contained in:
cansnow
2025-12-27 07:08:30 +08:00
parent 974d149d25
commit 09c7889525
54 changed files with 10485 additions and 164 deletions
@@ -31,11 +31,7 @@
return {
loadingWidth: "120px",
maxHeight:'120px',
src:"",
coverCachePath:"",
coverDownloading:false,
coverExists:false,
coverDownloadProgress:"",
src:""
};
},
computed: {
@@ -52,40 +48,11 @@
methods: {
async init(){
const self = this;
let url = "";
// 如果有远程 snapshotUrl,则下载到 coverCachePath
const snapshotUrl = this.message.FaceElem.data;
const key = md5(snapshotUrl || '');
this.coverCachePath = `_doc/${this.conversationID}/face_${key}.jpg`;
if (typeof plus === 'undefined' || !this.coverCachePath) return;
try {
// 检查封面是否存在
const coverExists = await util.fileExsit(self.coverCachePath);
this.coverExists = !!coverExists;
if (this.coverExists) {
this.src = this.coverCachePath;
return;
}
if (!snapshotUrl) {
this.src="/static/images/sync_error.png";
return;
}
this.coverDownloading = true;
await new Promise((resolve, reject) => {
util.downloadFile(snapshotUrl, self.coverCachePath, function(localPath) {
self.coverDownloading = false;
self.coverExists = true;
resolve(localPath);
}, function(err) {
self.coverDownloading = false;
reject(err);
}, function(progress) {
self.coverDownloadProgress = progress;
});
});
} catch (e) {
this.coverDownloading = false;
}
// 检查封面是否存在
util.cacheFile(snapshotUrl,'face').then((fn)=>{
self.src = fn;
});
},
onLoaded() {
this.loadingWidth = "auto";