mirror of
https://github.com/rubickCenter/rubick
synced 2026-03-09 23:40:24 +08:00
@@ -204,4 +204,38 @@ export default class DB {
|
||||
this.pouchDB = syncDb.pouchDB;
|
||||
await webdavClient.createReadStream(this.pouchDB);
|
||||
}
|
||||
|
||||
public async postAttachment(
|
||||
name: string,
|
||||
docId: string,
|
||||
attachment: Buffer | Uint8Array,
|
||||
type: string
|
||||
) {
|
||||
const buffer = Buffer.from(attachment);
|
||||
if (buffer.byteLength > this.docAttachmentMaxByteLength)
|
||||
return this.errorInfo(
|
||||
'exception',
|
||||
'attachment data up to ' +
|
||||
this.docAttachmentMaxByteLength / 1024 / 1024 +
|
||||
'M'
|
||||
);
|
||||
try {
|
||||
const result = await this.pouchDB.put({
|
||||
_id: this.getDocId(name, docId),
|
||||
_attachments: { 0: { data: buffer, content_type: type } },
|
||||
});
|
||||
result.id = this.replaceDocId(name, result.id);
|
||||
return result;
|
||||
} catch (e) {
|
||||
return this.errorInfo(e.name, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async getAttachment(name: string, docId: string, len = '0') {
|
||||
try {
|
||||
return await this.pouchDB.getAttachment(this.getDocId(name, docId), len);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ type WebDavOptions = {
|
||||
};
|
||||
|
||||
type DBInstance = {
|
||||
loadIt: (stream: unknown) => void;
|
||||
dump: (stream: unknown) => void;
|
||||
loadIt: (stream: unknown, options?: any) => void;
|
||||
dump: (stream: unknown, options?: any) => void;
|
||||
};
|
||||
|
||||
export default class WebDav {
|
||||
@@ -54,7 +54,12 @@ export default class WebDav {
|
||||
}).show();
|
||||
}
|
||||
const ws = new MemoryStream();
|
||||
dbInstance.dump(ws);
|
||||
dbInstance.dump(ws, {
|
||||
filter: (doc) => {
|
||||
// attachment 文档导出有问题,
|
||||
return !doc._attachments;
|
||||
},
|
||||
});
|
||||
ws.pipe(
|
||||
this.client.createWriteStream(this.cloudPath, {}, () => {
|
||||
new Notification({
|
||||
|
||||
@@ -157,13 +157,17 @@ class AdapterHandler {
|
||||
*/
|
||||
private async execCommand(cmd: string, modules: string[]): Promise<string> {
|
||||
return new Promise((resolve: any, reject: any) => {
|
||||
const args: string[] = [cmd]
|
||||
.concat(
|
||||
cmd !== 'uninstall' ? modules.map((m) => `${m}@latest`) : modules
|
||||
)
|
||||
.concat('--color=always')
|
||||
.concat('--save')
|
||||
.concat(`--registry=${this.registry}`);
|
||||
let args: string[] = [cmd].concat(
|
||||
cmd !== 'uninstall' && cmd !== 'link'
|
||||
? modules.map((m) => `${m}@latest`)
|
||||
: modules
|
||||
);
|
||||
if (cmd !== 'link') {
|
||||
args = args
|
||||
.concat('--color=always')
|
||||
.concat('--save')
|
||||
.concat(`--registry=${this.registry}`);
|
||||
}
|
||||
|
||||
const npm = spawn('npm', args, {
|
||||
cwd: this.baseDir,
|
||||
|
||||
Reference in New Issue
Block a user