|
|
|
@ -9,66 +9,62 @@ import path from 'node:path';
@@ -9,66 +9,62 @@ import path from 'node:path';
|
|
|
|
|
|
|
|
|
|
class TaJian { |
|
|
|
|
|
|
|
|
|
constructor(data_save_dir) { |
|
|
|
|
this.save_dir = data_save_dir; |
|
|
|
|
} |
|
|
|
|
constructor(data_save_dir) { |
|
|
|
|
this.save_dir = data_save_dir; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
* Example: |
|
|
|
|
[InternetShortcut] |
|
|
|
|
URL=https://microsoft.com/
|
|
|
|
|
*/ |
|
|
|
|
async saveUrlShortcut(filename, data) { |
|
|
|
|
//console.log('TaJian try to save shortcut url');
|
|
|
|
|
/* |
|
|
|
|
* Example: |
|
|
|
|
[InternetShortcut] |
|
|
|
|
URL=https://microsoft.com/
|
|
|
|
|
*/ |
|
|
|
|
async saveUrlShortcut(filename, data) { |
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
const dirPath = path.resolve(this.save_dir); |
|
|
|
|
const filepath = `${dirPath}/${filename}.url`; |
|
|
|
|
|
|
|
|
|
const dirPath = path.resolve(this.save_dir); |
|
|
|
|
const filepath = `${dirPath}/${filename}.url`; |
|
|
|
|
const shortUrlContent = `\[InternetShortcut\] |
|
|
|
|
URL=${data.url} |
|
|
|
|
`;
|
|
|
|
|
await writeFile(filepath, shortUrlContent, { encoding: 'utf8' }); |
|
|
|
|
}catch(error) { |
|
|
|
|
console.error('Save short url file failed: %s', error); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const shortUrlContent = `\[InternetShortcut\] |
|
|
|
|
URL=${data.url} |
|
|
|
|
`;
|
|
|
|
|
await writeFile(filepath, shortUrlContent, { encoding: 'utf8' }); |
|
|
|
|
}catch(error) { |
|
|
|
|
console.error('Save short url file failed: %s', error); |
|
|
|
|
return false; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async saveDescriptionFiles(filename, data) { |
|
|
|
|
//console.log('TaJian try to save description files');
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
const dirPath = path.resolve(this.save_dir); |
|
|
|
|
|
|
|
|
|
//save title
|
|
|
|
|
let filepath = `${dirPath}/${filename}_title.txt`; |
|
|
|
|
let content = data.title; |
|
|
|
|
await writeFile(filepath, content, { encoding: 'utf8' }); |
|
|
|
|
async saveDescriptionFiles(filename, data) { |
|
|
|
|
try { |
|
|
|
|
const dirPath = path.resolve(this.save_dir); |
|
|
|
|
|
|
|
|
|
if (typeof(data.cover_base64) != 'undefined' && data.cover_base64) { |
|
|
|
|
filepath = `${dirPath}/${filename}.${data.cover_type}`; |
|
|
|
|
content = Buffer.from(data.cover_base64, "base64"); //保存图片文件
|
|
|
|
|
//save title
|
|
|
|
|
let filepath = `${dirPath}/${filename}_title.txt`; |
|
|
|
|
let content = data.title; |
|
|
|
|
await writeFile(filepath, content, { encoding: 'utf8' }); |
|
|
|
|
|
|
|
|
|
filepath = `${dirPath}/${filename}_cover.txt`; |
|
|
|
|
content = `${filename}.${data.cover_type}`; //保存图片路径
|
|
|
|
|
await writeFile(filepath, content, { encoding: 'utf8' }); |
|
|
|
|
}else { |
|
|
|
|
filepath = `${dirPath}/${filename}_cover.txt`; |
|
|
|
|
content = data.cover; //保存图片网址
|
|
|
|
|
await writeFile(filepath, content, { encoding: 'utf8' }); |
|
|
|
|
if (typeof(data.cover_base64) != 'undefined' && data.cover_base64) { |
|
|
|
|
filepath = `${dirPath}/${filename}.${data.cover_type}`; |
|
|
|
|
content = Buffer.from(data.cover_base64, "base64"); //保存图片文件
|
|
|
|
|
await writeFile(filepath, content, { encoding: 'utf8' }); |
|
|
|
|
|
|
|
|
|
filepath = `${dirPath}/${filename}_cover.txt`; |
|
|
|
|
content = `${filename}.${data.cover_type}`; //保存图片路径
|
|
|
|
|
await writeFile(filepath, content, { encoding: 'utf8' }); |
|
|
|
|
}else { |
|
|
|
|
filepath = `${dirPath}/${filename}_cover.txt`; |
|
|
|
|
content = data.cover; //保存图片网址
|
|
|
|
|
await writeFile(filepath, content, { encoding: 'utf8' }); |
|
|
|
|
} |
|
|
|
|
}catch(error) { |
|
|
|
|
console.error('Save description files failed: %s', error); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
}catch(error) { |
|
|
|
|
console.error('Save description files failed: %s', error); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|