Commit ef0dc190 authored by martin hou's avatar martin hou

fix: 还原文件列表查询的实现,取消超时处理

parent 0aaa0fa0
......@@ -689,34 +689,25 @@ Jensen.prototype.getBluetoothStatus = async function (seconds) {
};
Jensen.prototype.listFiles = async function () {
let tag = 'filelist-' + this.serialNumber + '-' + this.sequence();
let tag = 'filelist-' + this.serialNumber;
if (this[tag] != null) return null;
let fc = null;
fc = await this.getFileCount(5);
fc = fc ? fc.count : 0;
// if (fc == null) return [];
if (typeof this.versionNumber == 'undefined' || this.versionNumber <= 327722) {
fc = await this.getFileCount(5);
if (fc == null) return null;
}
if (fc == 0) return [];
console.log('file count: ' + fc);
if (fc && fc.count == 0) return null;
let self = this;
// let tag = 'data_' + new Date().getTime();
this[tag] = [];
this[tag + '-ts'] = 0;
this.registerHandler(QUERY_FILE_LIST, (msg, jensen) => {
console.log('tag', tag);
if (msg.body.length == 0)
{
console.log('remove tag1: ' + tag);
if (msg.body.length == 0) {
jensen[tag] = null;
return [];
}
if (jensen[tag] == null)
{
console.trace('no tag for: ' + tag);
return 'x';
}
jensen[tag].push(msg.body);
let data = [];
let files = [];
......@@ -787,97 +778,35 @@ Jensen.prototype.listFiles = async function () {
{
duration = flen / 12;
}
else if (ver == 6)
{
duration = flen / 16;
}
let createDate = '';
let createTime = '';
if (ftime) {
createDate = ftime.getFullYear() + '/' + fnpad(ftime.getMonth() + 1) + '/' + fnpad(ftime.getDate());
createTime = fnpad(ftime.getHours()) + ':' + fnpad(ftime.getMinutes()) + ':' + fnpad(ftime.getSeconds());
}
let mode = 'room';
// 如果是旧的whisper mode
fname = fname.join('');
if (fname.match(/^.*REC\d+\.(hda|wav)$/gi))
{
mode = 'room';
}
else if (fname.match(/^.*WIP\d+\.(hda|wav)$/gi))
{
mode = 'whisper';
}
else if (fname.match(/^.*CALL\d+\.(hda|wav)$/gi))
{
mode = 'call';
}
else if (fname.match(/^.*ROOM\d+\.(hda|wav)$/gi))
{
mode = 'room';
}
else if (fname.match(/^.*WHSP\d+\.(hda|wav)$/gi))
{
mode = 'whisper';
}
files.push({
name: fname,
name: fname.join(''),
createDate: createDate,
createTime: createTime,
time: ftime,
duration: duration,
version: ver,
length: flen,
mode: mode,
signature: sign.join('')
});
// console.log(`Sign1: ${sign.join('')}, Sign2: ${sign2}`);
}
// if (fcount == -1 && (fc))
// 如果没有判断数量的依据
if (fcount == -1) {
// return [];
}
// 如果files有重复的signature,那就持续改为不重复的为止
// Check for duplicate signatures and regenerate if needed
const signatureCounts = {};
files.forEach(file => {
signatureCounts[file.signature] = (signatureCounts[file.signature] || 0) + 1;
});
// Only regenerate signatures for items that have duplicates
files.forEach(file => {
if (signatureCounts[file.signature] > 1) {
// Add timestamp to make signature unique
file.signature = md5(`${file.name}${file.length}`);
}
});
// 如果已经等待过长的时间了,那就直接返回好了
let kv = tag + '-timer';
let now = new Date().getTime();
if (kv in jensen)
{
window.clearTimeout(jensen[kv]);
}
jensen[kv] = now;
let ts = 2500;
if (fc == files.length)
{
return files.filter((f) => { return Boolean(f.time); });
}
jensen[tag + '-ts'] += 3000;
// console.log('ts, fc, files.length', ts, fc, files.length);
console.log(tag, 'timeout', jensen[tag + '-ts']);
jensen[kv] = window.setTimeout(() => {
console.log('remove tag: ' + tag);
if ((fc && files.length >= fc.count) || (fcount > -1 && files.length >= fcount)) {
// delete jensen[tag];
jensen[tag] = null;
jensen._trigger(files.filter((f) => { return Boolean(f.time); }), QUERY_FILE_LIST);
console.log('jensen', 'list-files', 'timed return');
}, jensen[tag + '-ts']);
return files.filter((f) => {
return Boolean(f.time);
});
}
});
return this.send(new Command(QUERY_FILE_LIST));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment