Remove importing and export from the ssb app. I like it better as the separate sneaker app.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4294 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-05-14 18:02:56 +00:00
parent ed4faedcd7
commit bc5bbca951
4 changed files with 1 additions and 108 deletions

View File

@ -14,7 +14,6 @@
<tf-app/>
<script>window.litDisableBundleWarning = true;</script>
<script src="filesaver.min.js"></script>
<script src="jszip.min.js"></script>
<script src="commonmark.min.js"></script>
<script src="commonmark-linkify.js" type="module"></script>
<script src="commonmark-hashtag.js" type="module"></script>

13
apps/ssb/jszip.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,6 @@ class TfProfileElement extends LitElement {
id: {type: String},
users: {type: Object},
size: {type: Number},
export_progress: {type: Object},
};
}
@ -25,7 +24,6 @@ class TfProfileElement extends LitElement {
this.id = null;
this.users = {};
this.size = 0;
this.export_progress = null;
}
modify(change) {
@ -123,48 +121,6 @@ class TfProfileElement extends LitElement {
return out;
}
async export() {
let all_messages = [];
let sequence = -1;
let messages_max = (await tfrpc.rpc.query('SELECT MAX(sequence) FROM messages WHERE author = ?', [this.id]))[0].sequence;
while (true) {
let messages = await tfrpc.rpc.query(
'SELECT * FROM messages WHERE author = ? AND SEQUENCE > ? ORDER BY sequence LIMIT 100',
[this.id, sequence]
);
if (messages?.length) {
all_messages = [].concat(all_messages, messages.map(x => this.format_message(x)));
sequence = messages[messages.length - 1].sequence;
this.export_progress = {name: 'messages', value: all_messages.length, max: messages_max};
} else {
break;
}
}
let zip = new JSZip();
zip.file('messages.txt', JSON.stringify(all_messages, null, 2));
let blobs = await tfrpc.rpc.query(
`SELECT blobs.id
FROM messages
JOIN messages_refs ON messages.id = messages_refs.message
JOIN blobs ON messages_refs.ref = blobs.id
WHERE messages.author = ?`,
[this.id]);
let blobs_done = 0;
for (let row of blobs) {
this.export_progress = {name: 'blobs', value: blobs_done, max: blobs.length};
let blob = await tfrpc.rpc.get_blob(row.id);
zip.folder('blobs').file(row.id.replaceAll('/', '_').replaceAll('+', '-'), blob);
blobs_done++;
}
this.export_progress = {name: 'saving'};
let blob = await zip.generateAsync({type: 'blob'});
saveAs(blob, `${this.id.replaceAll('/', '_').replaceAll('+', '-')}.zip`);
this.export_progress = null;
}
render() {
let self = this;
let profile = this.users[this.id] || {};
@ -212,14 +168,6 @@ class TfProfileElement extends LitElement {
</div>
<input type="button" value="Attach Image" @click=${this.attach_image}></input>
</div>` : null;
let export_state = html`<input type="button" value="Export" @click=${this.export}></input>`;
if (this.export_progress) {
if (this.export_progress.max) {
export_state = html`<span>${this.export_progress.name}</span><progress value=${this.export_progress.value} max=${this.export_progress.max}></progress>`;
} else {
export_state = html`<span>${this.export_progress.name}</span>`;
}
}
let image = typeof(profile.image) == 'string' ? profile.image : profile.image?.link;
image = this.editing?.image ?? image;
let description = this.editing?.description ?? profile.description;
@ -242,7 +190,6 @@ class TfProfileElement extends LitElement {
${edit}
${follow}
${block}
${export_state}
</div>
</div>`;
}

View File

@ -12,7 +12,6 @@ class TfTabNewsElement extends LitElement {
following: {type: Array},
drafts: {type: Object},
expanded: {type: Object},
import_progress: {type: Object},
};
}
@ -29,7 +28,6 @@ class TfTabNewsElement extends LitElement {
this.cache = {};
this.drafts = {};
this.expanded = {};
this.import_progress = null;
tfrpc.rpc.localStorageGet('drafts').then(function(d) {
self.drafts = JSON.parse(d || '{}');
});
@ -104,50 +102,12 @@ class TfTabNewsElement extends LitElement {
}
}
import_data() {
let self = this;
let input = document.createElement('input');
input.type = 'file';
input.onchange = async function(event) {
self.import_progress = {name: 'loading'};
let zip = new JSZip();
let file = await zip.loadAsync(event.target.files[0]);
let progress = 0;
let messages = JSON.parse(await file.file('messages.txt').async('string'));
for (let message of messages) {
self.import_progress = {name: 'messages', value: progress++, max: messages.length};
await tfrpc.rpc.store_message(message);
}
let blobs = [];
file.forEach(function(path, entry) {
if (path != 'messages.txt' && !entry.dir) {
blobs.push(entry);
}
});
progress = 0;
for (let blob of blobs) {
self.import_progress = {name: 'blobs', value: progress++, max: blobs.length};
console.log(await tfrpc.rpc.store_blob(await blob.async('arraybuffer')));
}
self.import_progress = undefined;
};
input.click();
}
render() {
let profile = this.hash.startsWith('#@') ?
html`<tf-profile id=${this.hash.substring(1)} whoami=${this.whoami} .users=${this.users}></tf-profile>` : undefined;
let import_state = html`<input type="button" value="Import" @click=${this.import_data}></input>`;
if (this.import_progress) {
if (this.import_progress.max) {
import_state = html`${this.import_progress.name} <progress value=${this.import_progress.value} max=${this.import_progress.max}></progress>`;
} else {
import_state = html`${this.import_progress.name} <progress></progress>`;
}
}
return html`
<div><input type="button" value=${this.new_messages_text()} @click=${this.show_more}></input></div>
<a target="_top" href="#" ?hidden=${this.hash.length <= 1}>🏠Home</a> ${import_state}
<a target="_top" href="#" ?hidden=${this.hash.length <= 1}>🏠Home</a>
<div>Welcome, <tf-user id=${this.whoami} .users=${this.users}></tf-user>!</div>
<div><tf-compose whoami=${this.whoami} .users=${this.users} .drafts=${this.drafts} @tf-draft=${this.draft}></tf-compose></div>
${profile}