Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
API: the admin drill-down leaves a workout's photos and videos out; /api/config says workouts may carry them
Duarte Santos3220d6a2222d
diff --git a/api/media.js b/api/media.jsindex dbea20253..6e456224f 100644--- a/api/media.js+++ b/api/media.js@@ -78,7 +78,10 @@ export function mediaLimits(env = process.env) {}/** The block GET /api/config hands out. Public: the caps are not a secret, and the editor needs* them before the first upload to refuse a file the server would refuse anyway. */-export const mediaConfig = l => ({ imageMB: l.imageMB, gifMB: l.gifMB, videoMB: l.videoMB, videoSec: l.videoSec, quotaMB: l.quotaMB });+// `workouts: true`: this server keeps the files a logged workout's `media` names (its GC walks+// workouts[].media), so a signed-in client may offer attaching them. A server from before says+// nothing, and the client offers them on custom exercises only.+export const mediaConfig = l => ({ imageMB: l.imageMB, gifMB: l.gifMB, videoMB: l.videoMB, videoSec: l.videoSec, quotaMB: l.quotaMB, workouts: true });/* ---------------------------------------------------------------- errors */diff --git a/api/openapi.yaml b/api/openapi.yamlindex 930acfe65..f98a1ac6f 100644--- a/api/openapi.yaml+++ b/api/openapi.yaml@@ -251,7 +251,7 @@ paths:allow_guest: falsecoach: { enabled: true, provider: compatible, providerLabel: "OpenAI-compatible endpoint", authMode: instance, community: false }passwordLogin: { value: { invite_only: true, allow_guest: false, password_login: true } }- media: { value: { invite_only: false, allow_guest: true, media: { imageMB: 2, gifMB: 8, videoMB: 40, videoSec: 60, quotaMB: 200 } } }+ media: { value: { invite_only: false, allow_guest: true, media: { imageMB: 2, gifMB: 8, videoMB: 40, videoSec: 60, quotaMB: 200, workouts: true } } }/api/me:get:@@ -1908,7 +1908,8 @@ paths:user. Admin only. Anything in `routines`, `bodyweight` or `workouts` that is notan object is left out, and a list that is not an array reads as empty: PUT/api/data drops those entries now, but a state file written before it did still- has them and this route has to answer for it.+ has them and this route has to answer for it. A workout's `media` (its photos and+ videos) is left out: they are the owner's own.parameters:- name: idin: query@@ -3124,7 +3125,14 @@ components:videoMB: { type: number }videoSec: { type: number }quotaMB: { type: number, description: Per profile; 0 = no cap. }- example: { imageMB: 2, gifMB: 8, videoMB: 40, videoSec: 60, quotaMB: 200 }+ workouts:+ type: boolean+ const: true+ description: >-+ This instance keeps the files a logged workout's `media` list names too, not only a+ custom exercise's. Absent on an instance from before; the app then offers photos and+ videos on custom exercises only.+ example: { imageMB: 2, gifMB: 8, videoMB: 40, videoSec: 60, quotaMB: 200, workouts: true }MediaUsage:type: objectdiff --git a/api/server.js b/api/server.jsindex acd93f614..3265fea5f 100644--- a/api/server.js+++ b/api/server.js@@ -2034,7 +2034,9 @@ const routes = {lastSync: S._ts || null,routines: records(S.routines).map(r => ({ id: r.id, name: r.name, emoji: r.emoji, count: records(r.ex).length })),bodyweight: records(S.bodyweight),- workouts: records(S.workouts).reverse() // records() already copied, so this reverse is ours: newest first for display+ // records() already copied, so this reverse is ours: newest first for display. A workout's+ // photos and videos are the owner's own: the admin view gets no refs to them.+ workouts: records(S.workouts).reverse().map(({ media, ...w }) => w)});},diff --git a/api/test/server-admin-state.test.js b/api/test/server-admin-state.test.jsindex 39e408ddf..351970256 100644--- a/api/test/server-admin-state.test.js+++ b/api/test/server-admin-state.test.js@@ -98,6 +98,17 @@ test('GET /api/admin/user opens a profile whose stored state predates the entryassert.equal(h.stackFrames(), 0, `stack traces in the log:\n${h.log}`);});+test('GET /api/admin/user leaves a workout\'s photos and videos out', async t => {+ const h = await startServer(t);+ const ref = { kind: 'image', hash: 'a'.repeat(64), mime: 'image/webp', size: 10, width: 8, height: 6, at: 1 };+ h.plant({ workouts: [{ ...okW, media: [ref] }], routines: [okR], bodyweight: [okB], unit: 'kg' });+ const r = await h.get(`/api/admin/user?id=${VICTIM}`);+ assert.equal(r.status, 200);+ assert.deepEqual(r.body.workouts.map(w => w.id), ['w1']);+ assert.equal('media' in r.body.workouts[0], false);+ assert.equal(JSON.stringify(r.body).includes('a'.repeat(64)), false);+});+test('the user list and the disable switch survive the same document', async t => {const h = await startServer(t);for (const [what, doc] of Object.entries(DOCS)) {diff --git a/api/test/server-media.test.js b/api/test/server-media.test.jsindex 061a8180a..ed4274036 100644--- a/api/test/server-media.test.js+++ b/api/test/server-media.test.js@@ -411,7 +411,7 @@ test('folders are 0700 and files 0600, and an admin deleting the profile removestest('/api/config carries the caps; MEDIA_UPLOADS=0 takes the block and every route away', async t => {const on = await start(t, { MEDIA_QUOTA_MB: '100', MEDIA_VIDEO_MAX_SEC: '30' });const cfg = await (await fetch(`${on.api}/api/config`)).json();- assert.deepEqual(cfg.media, { imageMB: 2, gifMB: 8, videoMB: 40, videoSec: 30, quotaMB: 100 });+ assert.deepEqual(cfg.media, { imageMB: 2, gifMB: 8, videoMB: 40, videoSec: 30, quotaMB: 100, workouts: true }); // `workouts`: a logged workout may carry them tooconst off = await start(t, { MEDIA_UPLOADS: '0' });const cfgOff = await (await fetch(`${off.api}/api/config`)).json();