diff --git a/js/projects.js b/js/projects.js index 660baf5..c2b64ab 100644 --- a/js/projects.js +++ b/js/projects.js @@ -4278,6 +4278,7 @@ function prepare_storDia(){ function downloadFile(filename) { let url = "store/" + globalUserName + "/" + globalProjectName + "/" + filename; + console.log(url) let a = document.createElement('a'); a.href = url; a.download = filename; @@ -4367,11 +4368,32 @@ function prepare_storDia(){ var sortedRes = res.sort(function(a, b) { // 提取时间戳 let getTimestamp = function(filename) { - if(filename.split("_").length>1) { - return parseInt(filename.split("_")[1].split('.')[0]); + // 提取文件名中的时间部分 + let timePart; + if(filename.split("_").length > 1) { + timePart = filename.split("_").slice(1).join('-').split('.')[0]; } else { - return parseInt(filename.split('.')[0]); + timePart = filename.split('.')[0]; } + + // 检查是否是纯数字(时间戳) + if(/^\d+$/.test(timePart)) { + return parseInt(timePart); + } + + // 尝试解析 YYYY-MM-DD HH:MM:SS 格式 + const datePattern = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/; + const match = timePart.match(datePattern); + + if(match) { + const [_, year, month, day, hours, minutes, seconds] = match; + const date = new Date(`${year}-${month}-${day}T${hours}:${minutes}:${seconds}`); + return date.getTime(); // 返回时间戳 + } + + // 如果都不匹配,可以返回0或者抛出错误,根据你的需求 + return 0; + // 或者 throw new Error("Invalid time format in filename"); }; let timeA = getTimestamp(a); @@ -4393,12 +4415,26 @@ function prepare_storDia(){ } let isText = filename.endsWith('.txt'); let timeStamp; + let timeString; if(filename.split("_").length>1) { - timeStamp = parseInt(filename.split("_")[1].split('.')[0]) + if(/^\d+$/.test(filename.split("_").slice(1).join('-').split('.')[0])) { + timeStamp = parseInt(filename.split("_").slice(1).join('-').split('.')[0]) + timeString = new Date(timeStamp).toLocaleString(); + } + else{ + timeStamp = filename.split("_").slice(1).join('-').split('.')[0] + timeString = timeStamp.substring(0,4) + "/" + timeStamp.substring(5,7) + "/" + timeStamp.substring(8,10) + " " + timeStamp.substring(11,13) + ":" + timeStamp.substring(14,16) + ":" + timeStamp.substring(17,19) + } } else { - timeStamp = parseInt(filename.split('.')[0]); + if(/^\d+$/.test(filename.split('.')[0])) { + timeStamp = parseInt(filename.split('.')[0]) + timeString = new Date(timeStamp).toLocaleString(); + } + else{ + timeStamp = filename.split('.')[0] + timeString = new Date(timeStamp).toLocaleString(); + } } - let timeString = new Date(timeStamp).toLocaleString(); let fileType = isText ? '文本' : '图片'; // List view row @@ -4473,7 +4509,7 @@ function prepare_storDia(){ tableBody.append(row); // Grid view item - let gridItem = $('
'); + let gridItem = $('
'); // File preview let previewDiv = $('
'); @@ -4481,7 +4517,7 @@ function prepare_storDia(){ if (isText) { previewDiv.append(''); } else { - previewDiv.append(''); + previewDiv.append(''); } previewDiv.click(function() { @@ -4514,10 +4550,9 @@ function prepare_storDia(){ // Filename (truncated) let shortName = filename.length > 20 ? filename.substring(0, 17) + '...' : filename; - infoDiv.append('
' + shortName + '
'); + infoDiv.append('
' + shortName + '
'); // File type and date - infoDiv.append('
' + fileType + '
'); infoDiv.append('
' + timeString + '
'); gridItem.append(infoDiv); diff --git a/mixio.js b/mixio.js index 45a7d53..d0d0f39 100644 --- a/mixio.js +++ b/mixio.js @@ -841,7 +841,8 @@ var mixioServer = async function() { if (match && allowFormats.includes(match[1])) { // 是base64 const format = match[1]; - const timeStamp = Date.now(); + const currentDate = new Date(); + const timeStamp = `${currentDate.getFullYear()}_${(currentDate.getMonth() + 1).toString().padStart(2, '0')}_${currentDate.getDate().toString().padStart(2, '0')}_${currentDate.getHours().toString().padStart(2, '0')}_${currentDate.getMinutes().toString().padStart(2, '0')}_${currentDate.getSeconds().toString().padStart(2, '0')}`; const fileName = topic[3] + '_' + `${timeStamp}.${format}`; const filePath = path.join('store', topic[0], topic[1], topic[2], fileName); const base64Data = payload.replace(base64Reg, ''); @@ -850,7 +851,8 @@ var mixioServer = async function() { fs.writeFileSync(filePath, buffer); } else { // 全部明文存为txt - const timeStamp = Date.now(); + const currentDate = new Date(); + const timeStamp = `${currentDate.getFullYear()}_${(currentDate.getMonth() + 1).toString().padStart(2, '0')}_${currentDate.getDate().toString().padStart(2, '0')}_${currentDate.getHours().toString().padStart(2, '0')}_${currentDate.getMinutes().toString().padStart(2, '0')}_${currentDate.getSeconds().toString().padStart(2, '0')}`; const fileName = topic[3] + '_' + `${timeStamp}.txt`; const filePath = path.join('store', topic[0], topic[1], topic[2], fileName); fs.mkdirSync(path.dirname(filePath), { recursive: true}); @@ -868,7 +870,8 @@ var mixioServer = async function() { if (match && allowFormats.includes(match[1])) { // 是base64 const format = match[1]; - const timeStamp = Date.now(); + const currentDate = new Date(); + const timeStamp = `${currentDate.getFullYear()}_${(currentDate.getMonth() + 1).toString().padStart(2, '0')}_${currentDate.getDate().toString().padStart(2, '0')}_${currentDate.getHours().toString().padStart(2, '0')}_${currentDate.getMinutes().toString().padStart(2, '0')}_${currentDate.getSeconds().toString().padStart(2, '0')}`; const fileName = topic[2] + '_' + `${timeStamp}.${format}`; const filePath = path.join('store', topic[0], topic[1], fileName); const base64Data = payload.replace(base64Reg, ''); @@ -877,7 +880,8 @@ var mixioServer = async function() { fs.writeFileSync(filePath, buffer); } else { // 全部明文存为txt - const timeStamp = Date.now(); + const currentDate = new Date(); + const timeStamp = `${currentDate.getFullYear()}_${(currentDate.getMonth() + 1).toString().padStart(2, '0')}_${currentDate.getDate().toString().padStart(2, '0')}_${currentDate.getHours().toString().padStart(2, '0')}_${currentDate.getMinutes().toString().padStart(2, '0')}_${currentDate.getSeconds().toString().padStart(2, '0')}`; const fileName = topic[2] + '_' + `${timeStamp}.txt`; const filePath = path.join('store', topic[0], topic[1], fileName); fs.mkdirSync(path.dirname(filePath), { recursive: true});