2019-01-16 05:33:06 +01:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import { unpackDirectory } from 'lbry-format';
|
|
|
|
|
|
|
|
async function unpackByOutpoint(lbry, outpoint) {
|
2019-11-05 21:16:41 +01:00
|
|
|
const { items: claimFiles } = await lbry.file_list({ outpoint, full_status: true, page: 1, page_size: 1 });
|
2019-01-16 05:33:06 +01:00
|
|
|
|
|
|
|
if (claimFiles && claimFiles.length) {
|
|
|
|
const claimFileInfo = claimFiles[0];
|
|
|
|
const packFilePath = path.resolve(claimFileInfo.download_path);
|
2019-05-07 23:38:29 +02:00
|
|
|
const unpackPath = path.normalize(path.join(claimFileInfo.download_directory, claimFileInfo.claim_name));
|
2019-01-16 05:33:06 +01:00
|
|
|
|
|
|
|
if (!fs.existsSync(unpackPath)) {
|
|
|
|
await unpackDirectory(unpackPath, {
|
|
|
|
fileName: packFilePath,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return unpackPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default unpackByOutpoint;
|