publish 功能
This commit is contained in:
+12
-8
@@ -9,7 +9,7 @@ const { pipeline, Transform} = require("stream/promises");
|
||||
module.exports = class Remote {
|
||||
|
||||
constructor() {
|
||||
this.init()
|
||||
// this.__init()
|
||||
this.func_publish = require("./publish")
|
||||
this.func_install = require("./install")
|
||||
}
|
||||
@@ -21,12 +21,14 @@ module.exports = class Remote {
|
||||
const uConfig = await $context.get("uConfig");
|
||||
if ( uConfig.get("remoteServer") ){
|
||||
let server = uConfig.get("remoteServer");
|
||||
$logger.info("server " + server)
|
||||
if ( server.startsWith("webdav") ) {
|
||||
server = "http" + server.substring(6)
|
||||
}
|
||||
|
||||
if ( uConfig.get("remoteAuth") ) {
|
||||
let up = uConfig.get("remoteAuth");
|
||||
$logger.info("remoteAuth " + up)
|
||||
up = up.split(":", 2)
|
||||
this.client = this.webdav.createClient(
|
||||
server,
|
||||
@@ -155,29 +157,31 @@ module.exports = class Remote {
|
||||
return false;
|
||||
}
|
||||
|
||||
async publish(){
|
||||
return this.func_publish( this )
|
||||
async publish(localFile, remotePath){
|
||||
return await this.func_publish( this , localFile, remotePath )
|
||||
}
|
||||
|
||||
async install(id){
|
||||
return this.func_install( this, id )
|
||||
}
|
||||
|
||||
async wUpload(from, to){
|
||||
async wUpload(from, to, debug){
|
||||
const totalSize = fs.statSync(from).size;
|
||||
debug ? console.log("totalSize", totalSize) : null
|
||||
const rs = fs.createReadStream( from );
|
||||
let wSize = 0;
|
||||
let rSize = 0;
|
||||
rs.on("data", (r)=>{
|
||||
rSize += r.length;
|
||||
// console.log("r", rSize * 100 / totalSize)
|
||||
debug ? console.log("r", rSize * 100 / totalSize + "%") : null
|
||||
})
|
||||
const ws = this.client.createWriteStream(to)
|
||||
ws.on("data", (r)=>{
|
||||
wSize += r.length;
|
||||
// console.log("w", wSize * 100 / totalSize)
|
||||
debug ? console.log("w ", wSize * 100 / totalSize + "%") : null
|
||||
})
|
||||
return pipeline( rs, ws);
|
||||
await pipeline( rs, ws);
|
||||
debug ? console.log("finish") : null
|
||||
}
|
||||
|
||||
async wDownload(from, to){
|
||||
@@ -198,7 +202,7 @@ module.exports = class Remote {
|
||||
wSize += r.length;
|
||||
// console.log("w", wSize * 100 / totalSize)
|
||||
})
|
||||
return pipeline(
|
||||
return await pipeline(
|
||||
rs, ws
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user