Fix GPX upload.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4396 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-08-12 18:37:15 +00:00
parent 07b1a0e403
commit e10803de68

View File

@ -65,6 +65,7 @@ class GgAppElement extends LitElement {
async get_activities_from_ssb() { async get_activities_from_ssb() {
this.status = {text: 'loading activities'}; this.status = {text: 'loading activities'};
this.loaded_activities = [];
let blob_ids = await tfrpc.rpc.query(` let blob_ids = await tfrpc.rpc.query(`
SELECT json_extract(mention.value, '$.link') AS blob_id SELECT json_extract(mention.value, '$.link') AS blob_id
FROM messages_fts('"gg-activity"') FROM messages_fts('"gg-activity"')
@ -165,7 +166,6 @@ class GgAppElement extends LitElement {
} }
let shared = await tfrpc.rpc.sharedDatabaseGet(name); let shared = await tfrpc.rpc.sharedDatabaseGet(name);
if (shared) { if (shared) {
console.log('shared =', shared);
await tfrpc.rpc.databaseSet('strava', shared); await tfrpc.rpc.databaseSet('strava', shared);
await tfrpc.rpc.sharedDatabaseRemove(name); await tfrpc.rpc.sharedDatabaseRemove(name);
} }
@ -446,7 +446,6 @@ class GgAppElement extends LitElement {
} }
} }
if (activity?.segments) { if (activity?.segments) {
console.log('have a gpx');
for (let segment of activity.segments) { for (let segment of activity.segments) {
let last; let last;
for (let pt of segment) { for (let pt of segment) {
@ -464,11 +463,13 @@ class GgAppElement extends LitElement {
} }
async on_upload(event) { async on_upload(event) {
try {
let file = event.srcElement.files[0]; let file = event.srcElement.files[0];
let xml = await file.text(); let xml = await file.text();
let gpx = gpx_parse(xml); let gpx = gpx_parse(xml);
let blob_id = await tfrpc.rpc.store_blob(xml); let blob_id = await tfrpc.rpc.store_blob(xml);
console.log('blob_id = ', blob_id); console.log('blob_id = ', blob_id);
console.log(gpx);
let message = { let message = {
type: 'gg-activity', type: 'gg-activity',
mentions: [ mentions: [
@ -482,19 +483,20 @@ class GgAppElement extends LitElement {
} }
], ],
}; };
console.log('message = ', message); console.log('id =', this.id, 'message = ', message);
try {
let id = await tfrpc.rpc.appendMessage(this.id, message); let id = await tfrpc.rpc.appendMessage(this.id, message);
console.log('appended message', id); console.log('appended message', id);
alert('Activity uploaded.');
await this.get_activities_from_ssb();
} catch (e) { } catch (e) {
console.log('augh', e); alert(`Error: ${JSON.stringify(e, null, 2)}`);
} }
} }
upload() { upload() {
let input = document.createElement('input'); let input = document.createElement('input');
input.type = 'file'; input.type = 'file';
input.onchange = this.on_upload; input.onchange = (event) => this.on_upload(event);
input.click(); input.click();
} }
@ -504,17 +506,23 @@ class GgAppElement extends LitElement {
} }
if (!this.strava?.access_token) { if (!this.strava?.access_token) {
let strava_url = `https://www.strava.com/oauth/authorize?client_id=${k_client_id}&redirect_uri=${k_redirect_url}&response_type=code&approval_prompt=auto&scope=activity%3Aread&state=${g_data.state}`; let strava_url = `https://www.strava.com/oauth/authorize?client_id=${k_client_id}&redirect_uri=${k_redirect_url}&response_type=code&approval_prompt=auto&scope=activity%3Aread&state=${g_data.state}`;
return html`<div>Please <a target="_top" href=${strava_url}>login</a> to Strava.</div>`; return html`
<div style="display: flex; flex-direction: row; align-items: center; gap: 1em; width: 100%">
<div style="flex: 1 1">Please <a target="_top" href=${strava_url}>login</a> to Strava.</div>
<span style="font-size: xx-small; flex: 1 1; word-break: break-all">${this.id}</span>
<input type="button" value="📁" @click=${this.upload}></input>
</div>
`;
} }
return html` return html`
<div> <div>
<h1> <div style="display: flex; flex-direction: row; align-items: center; gap: 1em; width: 100%">
Welcome, ${this.user.credentials.session.name} <h1>Welcome, ${this.user.credentials.session.name}</h1>
<span style="font-size: xx-small">${this.id}</span> <span style="font-size: xx-small; flex: 1 1; word-break: break-all">${this.id}</span>
<input type="button" value="📁" @click=${this.upload}></input> <input type="button" value="📁" @click=${this.upload}></input>
</h1> </div>
<h3>${this.status?.text} <progress ?hidden=${!this.status?.max} value=${this.status?.value} max=${this.status?.max}>${this.status?.value}</progress></h3> <h3 ?hidden=${!this.status?.text}>${this.status?.text} <progress ?hidden=${!this.status?.max} value=${this.status?.value} max=${this.status?.max}>${this.status?.value}</progress></h3>
</div> </div>
`; `;
} }