Commit 7f27a5e9 authored by martin hou's avatar martin hou

fix: 恢复文件列表查询实现

parent d0ee92e4
...@@ -704,32 +704,25 @@ Jensen.prototype.getBluetoothStatus = async function (seconds) { ...@@ -704,32 +704,25 @@ Jensen.prototype.getBluetoothStatus = async function (seconds) {
}; };
Jensen.prototype.listFiles = async function () { Jensen.prototype.listFiles = async function () {
let tag = 'filelist-' + this.serialNumber + '-' + this.sequence(); let tag = 'filelist-' + this.serialNumber;
if (this[tag] != null) return null; if (this[tag] != null) return null;
let fc = null; let fc = null;
fc = await this.getFileCount(5); if (typeof this.versionNumber == 'undefined' || this.versionNumber <= 327722) {
if (fc == null) return []; fc = await this.getFileCount(5);
if (fc && fc.count == 0) return []; if (fc == null) return null;
else fc = fc.count; }
Logger.info('jensen', 'cmd', 'file count: ' + fc);
if (fc && fc.count == 0) return null;
let self = this; let self = this;
// let tag = 'data_' + new Date().getTime(); // let tag = 'data_' + new Date().getTime();
this[tag] = []; this[tag] = [];
this.registerHandler(QUERY_FILE_LIST, (msg, jensen) => { this.registerHandler(QUERY_FILE_LIST, (msg, jensen) => {
console.log('tag', tag); if (msg.body.length == 0) {
if (msg.body.length == 0)
{
console.log('remove tag1: ' + tag);
jensen[tag] = null; jensen[tag] = null;
return []; return [];
} }
if (jensen[tag] == null)
{
console.trace('no tag for: ' + tag);
return 'x';
}
jensen[tag].push(msg.body); jensen[tag].push(msg.body);
let data = []; let data = [];
let files = []; let files = [];
...@@ -800,58 +793,29 @@ Jensen.prototype.listFiles = async function () { ...@@ -800,58 +793,29 @@ Jensen.prototype.listFiles = async function () {
{ {
duration = flen / 12; duration = flen / 12;
} }
else if (ver == 6)
{
duration = flen / 16;
}
let createDate = ''; let createDate = '';
let createTime = ''; let createTime = '';
if (ftime) { if (ftime) {
createDate = ftime.getFullYear() + '/' + fnpad(ftime.getMonth() + 1) + '/' + fnpad(ftime.getDate()); createDate = ftime.getFullYear() + '/' + fnpad(ftime.getMonth() + 1) + '/' + fnpad(ftime.getDate());
createTime = fnpad(ftime.getHours()) + ':' + fnpad(ftime.getMinutes()) + ':' + fnpad(ftime.getSeconds()); 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({ files.push({
name: fname, name: fname.join(''),
createDate: createDate, createDate: createDate,
createTime: createTime, createTime: createTime,
time: ftime, time: ftime,
duration: duration, duration: duration,
version: ver, version: ver,
length: flen, length: flen,
mode: mode,
signature: sign.join('') signature: sign.join('')
}); });
// console.log(`Sign1: ${sign.join('')}, Sign2: ${sign2}`);
} }
// if (fcount == -1 && (fc)) // if (fcount == -1 && (fc))
// 如果没有判断数量的依据 // 如果没有判断数量的依据
if (fcount == -1) { if (fcount == -1) {
// return []; // return [];
} }
// 如果files有重复的signature,那就持续改为不重复的为止 // 如果files有重复的signature,那就持续改为不重复的为止
// Check for duplicate signatures and regenerate if needed // Check for duplicate signatures and regenerate if needed
const signatureCounts = {}; const signatureCounts = {};
...@@ -867,28 +831,14 @@ Jensen.prototype.listFiles = async function () { ...@@ -867,28 +831,14 @@ Jensen.prototype.listFiles = async function () {
} }
}); });
// 如果已经等待过长的时间了,那就直接返回好了 if ((fc && files.length >= fc.count) || (fcount > -1 && files.length >= fcount)) {
let kv = tag + '-timer'; // delete jensen[tag];
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); });
}
else if (fc > 0 && fc - files.length < 10) ts = 1000;
else ts = 15000;
jensen[kv] = window.setTimeout(() => {
console.log('remove tag: ' + tag);
jensen[tag] = null; jensen[tag] = null;
jensen._trigger(files.filter((f) => { return Boolean(f.time); }), QUERY_FILE_LIST); console.log('original file list:', files);
console.log('jensen', 'list-files', 'timed return'); return files.filter((f) => {
}, ts); return Boolean(f.time);
});
}
}); });
return this.send(new Command(QUERY_FILE_LIST)); 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