Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ The version numbers are explained in "Project status" in the [README](README.md)

### Added

- Every moment in the REST payload and in the sync pull has `width` and `height`: the pixel size of the photo or video as it is shown, after the EXIF orientation of a photo and the rotation of a video. They are `null` for story, milestone and growth moments and for a video that is still processing. The app can lay out the timeline before an image loads.
- `php artisan kinlore:media-dimensions` fills `width` and `height` of older photos and videos. Run it once after this update. An older photo gets the size of its 1200-pixel preview, so the ratio is exact but the size can be smaller than the original. It skips and counts files it cannot read, and `--dry-run` changes nothing. Phones get the sizes at their next sync. See [Updating](docs/self-hosting/updating.md#from-1-5-to-1-6).
- `POST /auth/login` and `POST /auth/register` accept an optional `device_name` (up to 60 characters). It is the session `name` in `GET /auth/sessions`, so the app can show each signed-in device. Without it the name stays `mobile-app`. `POST /auth/refresh` keeps the name.

### Fixed
Expand All @@ -22,6 +24,10 @@ The version numbers are explained in "Project status" in the [README](README.md)
- `POST /v1/invitations` returns `public_url_configured` (bool), so the app can tell the admin to set `APP_URL`. `GET /health/detailed` has a `public_url` check, and `php artisan kinlore:setup-token` prints a warning.
- `openapi.yaml` describes `device_name`, the session `name`, `public_url_configured` in `POST /v1/invitations` and the `public_url` check of `GET /health/detailed`.

### Upgrade notes

- **Docker and host install:** after the update, run `php artisan kinlore:media-dimensions` once. It fills the size of the photos and videos that you already have. See [Updating](docs/self-hosting/updating.md#from-1-5-to-1-6).

## [1.5.1] - 2026-11-26

Use this release with version 1.2.0 or newer of the mobile app. The update needs no manual step.
Expand Down
6 changes: 4 additions & 2 deletions docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ Kid payload: `{ id, user_id, name, date_of_birth: "YYYY-MM-DD"|null, due_date: "
Types: `photo`, `video`, `story`, `milestone`, `growth`.

Moment payload (REST and the inside of `data.moment`):
`{ id, kid_id, user_id: int|null, uploader_name: string|null, moment_type, title, description, milestone_id, exif_date (ISO|null), display_date (ISO, exif_date or created_at), latitude: number|null, longitude: number|null, orientation, camera_make, camera_model, file_size, mime_type, original_filename, device_asset_id, duration: number|null (seconds), video_status: "processing"|"ready"|"failed"|null, height_cm: number|null, weight_kg: number|null, head_circumference_cm: number|null, likes_count, comments_count, is_liked, created_at, updated_at, media?: {...}, milestone?: {...} }`. It has no file links: the app uses `/file/{type}` and `/playback`.
`{ id, kid_id, user_id: int|null, uploader_name: string|null, moment_type, title, description, milestone_id, exif_date (ISO|null), display_date (ISO, exif_date or created_at), latitude: number|null, longitude: number|null, orientation, width: int|null, height: int|null, camera_make, camera_model, file_size, mime_type, original_filename, device_asset_id, duration: number|null (seconds), video_status: "processing"|"ready"|"failed"|null, height_cm: number|null, weight_kg: number|null, head_circumference_cm: number|null, likes_count, comments_count, is_liked, created_at, updated_at, media?: {...}, milestone?: {...} }`. It has no file links: the app uses `/file/{type}` and `/playback`.

`width` and `height` are the pixel size of the photo or video as it is shown: after the EXIF orientation of a photo and after the rotation of a video. They are `null` for story, milestone and growth moments, for a video that is still processing, and for an older photo or video that `php artisan kinlore:media-dimensions` has not filled. For an older photo, that command stores the size of the 1200-pixel preview: the ratio is right, the size can be smaller than the original.

- `POST /v1/moments`:
- photo/video: multipart `kid_id, file (required, also with moment_type=photo|video), title?, description?, device_asset_id?, exif_date?, latitude?, longitude?, camera_make?, camera_model?, orientation?`.
Expand Down Expand Up @@ -161,7 +163,7 @@ Response: `{ changes: { kids: {created, updated, deleted}, moments: {created, up
- The server returns rows with `updated_at >= lastPulledAt - 1000` (database times have second precision). The client must therefore **upsert** every row in `created` and `updated` (insert when missing, otherwise update all fields). Rows may come again.
- `deleted`: ids of kids and moments soft-deleted since `lastPulledAt - 1000`, including the moments of deleted kids.
- Kid row: `{ id, user_id, name, date_of_birth, due_date, avatar_color, created_at, updated_at }` (times in ms, dates as ms at UTC midnight, or null).
- Moment row: `{ id, kid_id, user_id, uploader_name, moment_type, title, description, milestone_id, exif_date, latitude, longitude, orientation, duration, video_status, height_cm, weight_kg, head_circumference_cm, likes_count, comments_count, is_liked, file_size, mime_type, device_asset_id, created_at, updated_at }`. No file fields. `is_liked` is for the caller.
- Moment row: `{ id, kid_id, user_id, uploader_name, moment_type, title, description, milestone_id, exif_date, latitude, longitude, orientation, width, height, duration, video_status, height_cm, weight_kg, head_circumference_cm, likes_count, comments_count, is_liked, file_size, mime_type, device_asset_id, created_at, updated_at }`. No file fields. `width` and `height` are as in the moment payload (section 6). `is_liked` is for the caller.

`POST /v1/sync/push` request: `{ changes: { kids: {created, updated, deleted}, moments: {created, updated, deleted} }, lastPulledAt }`.
- Kid fields: `id, name, date_of_birth (ms|null), due_date (ms|null), avatar_color`. The server keeps the client `id`.
Expand Down
1 change: 1 addition & 0 deletions docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This page lists the commands that a server owner uses. Artisan is the command to
|---|---|
| `php artisan kinlore:setup-token` | Prints the token that the setup page asks for, while the server has no user. With `SETUP_TOKEN` set, it tells you to use that value. See [Create the first admin](/self-hosting/first-admin). |
| `php artisan kinlore:reset-password <email>` | Sets a new password for a user and signs them out on all devices. It asks for the password. `--password=<new password>` gives it on the command line instead; the password then shows in the shell history. The password needs at least 8 characters. |
| `php artisan kinlore:media-dimensions` | Fills the width and height of older photos and videos, so the app can lay out the timeline before the images load. Run it once after the update to 1.6. A video gets the size that its conversion saved. A photo gets the size of its preview: the real size up to 1200 pixels wide, else the same ratio at 1200 pixels wide. It works in groups of 200 and changes only moments without a size, so you can run it again at any time. A file that it cannot read is skipped, counted in the result and written to the log. `--dry-run` shows the counts and changes nothing. Phones get the new sizes at their next sync. |
| `php artisan seaweedfs:test` | Writes, reads, lists and deletes a test file in the media storage, then prints the storage settings. It works for S3 storage and the local disk. |

## Laravel commands
Expand Down
12 changes: 12 additions & 0 deletions docs/self-hosting/updating.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ On a host install, also check the workers: `systemctl is-active kinlore-queue ki

Do the steps of every version between your version and the new one, oldest first.

### From 1.5 to 1.6

**Docker and host install**

After the update, fill the size of the photos and videos that you already have. The app needs it for the timeline. Run this command once (see [How to run an Artisan command](/reference/commands#how-to-run-an-artisan-command)):

```sh [Fill the media sizes]
php artisan kinlore:media-dimensions
```

It reads one small preview per photo, so it can take some minutes on a large library. The last line shows how many moments it filled and how many files it could not read. Phones get the sizes at their next sync. New uploads get their size by themselves.

### From 1.3 to 1.4

**Docker**
Expand Down
75 changes: 75 additions & 0 deletions kinlore-api/app/Console/Commands/MediaDimensions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Enums\MomentType;
use App\Enums\VideoStatus;
use App\Models\Moment;
use App\Services\FileStorageService;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

/**
* Run once after the update that added moment sizes (docs/reference/commands.md): fills the display size of older photos and videos.
* A video gets the size its processing saved. A photo gets the size of its medium preview (oriented, aspect kept):
* the real size up to 1200 pixels wide, else that ratio at 1200 pixels wide, because the original size was never saved.
*/
#[Signature('kinlore:media-dimensions {--dry-run : Show what would be filled, change nothing}')]
#[Description('Fill the width and height of photo and video moments that have none')]
class MediaDimensions extends Command
{
public function handle(FileStorageService $storage): int
{
$dryRun = (bool) $this->option('dry-run');
$filled = 0;
$unreadable = 0;

Moment::query()
->with('media:id,video_metadata')
->whereIn('moment_type', [MomentType::Photo, MomentType::Video])
->where(fn ($q) => $q->whereNull('width')->orWhereNull('height'))
// A video still processing gets its size from the job; a failed one has no preview.
->where(fn ($q) => $q->whereNull('video_status')->orWhere('video_status', VideoStatus::Ready))
->chunkById(200, function ($moments) use ($storage, $dryRun, &$filled, &$unreadable): void {
foreach ($moments as $moment) {
$size = $this->size($moment, $storage);
if (! $size) {
$unreadable++;
Log::warning('kinlore:media-dimensions cannot read the size', ['moment_id' => $moment->id]);

continue;
}

// A query update: updated_at changes, so phones get the row on their next sync; edited_at
// stays, so this is no edit and causes no sync conflict.
if (! $dryRun) {
Moment::whereKey($moment->id)->update($size);
}
$filled++;
}
});

$this->info(($dryRun ? 'Would fill' : 'Filled')." {$filled} moments. Cannot read {$unreadable}.");

return self::SUCCESS;
}

/** @return array{width: int, height: int}|null */
private function size(Moment $moment, FileStorageService $storage): ?array
{
$metadata = $moment->media?->video_metadata;
if (($metadata['width'] ?? 0) > 0 && ($metadata['height'] ?? 0) > 0) {
return ['width' => (int) $metadata['width'], 'height' => (int) $metadata['height']];
}

$path = $moment->getRawOriginal('medium_url');
$bytes = $path ? $storage->get($path) : null;
$info = $bytes ? @getimagesizefromstring($bytes) : false;

return $info && $info[0] > 0 && $info[1] > 0 ? ['width' => $info[0], 'height' => $info[1]] : null;
}
}
6 changes: 6 additions & 0 deletions kinlore-api/app/Models/Moment.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
'latitude',
'longitude',
'orientation',
'width',
'height',
'camera_make',
'camera_model',
'duration',
Expand Down Expand Up @@ -83,6 +85,8 @@ protected function casts(): array
'weight_kg' => 'float',
'head_circumference_cm' => 'float',
'orientation' => 'integer',
'width' => 'integer',
'height' => 'integer',
'moment_type' => MomentType::class,
'video_status' => VideoStatus::class,
];
Expand Down Expand Up @@ -200,6 +204,8 @@ public function toArray(): array
'longitude' => $this->longitude,
'has_location' => $this->has_location,
'orientation' => $this->orientation,
'width' => $this->width,
'height' => $this->height,
'camera_make' => $this->camera_make,
'camera_model' => $this->camera_model,
'duration' => $this->duration,
Expand Down
32 changes: 19 additions & 13 deletions kinlore-api/app/Services/MomentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,8 @@ private function createMediaMoment(User $user, Kid $kid, UploadedFile $file, arr
'processing_started_at' => now(),
]);

// Videos are processed by a queued job so the upload returns at once
if ($type === MomentType::Photo) {
$this->processPhoto($media, $file, $basePath);
}
// Videos are processed by a queued job so the upload returns at once; it sets their size
$size = $type === MomentType::Photo ? $this->processPhoto($media, $file, $basePath) : [];

$media->refresh();
$moment = Moment::create([
Expand All @@ -162,7 +160,7 @@ private function createMediaMoment(User $user, Kid $kid, UploadedFile $file, arr
'camera_make' => $media->camera_make,
'camera_model' => $media->camera_model,
'video_status' => $type === MomentType::Video ? VideoStatus::Processing : null,
]);
] + $size);
} catch (\Throwable $e) {
Log::error('Media upload failed: '.$e->getMessage());
$media?->forceDelete();
Expand Down Expand Up @@ -213,7 +211,8 @@ private function createTextMoment(User $user, Kid $kid, array $data, MomentType
return ['moment' => $moment];
}

private function processPhoto(Media $media, UploadedFile $file, string $basePath): void
/** @return array{width: int, height: int} display size of the photo */
private function processPhoto(Media $media, UploadedFile $file, string $basePath): array
{
$thumbnailPath = "{$basePath}/thumbnail.jpg";
$mediumPath = "{$basePath}/medium.jpg";
Expand All @@ -230,7 +229,7 @@ private function processPhoto(Media $media, UploadedFile $file, string $basePath
$source = $decoded;
}

$this->storePreviews($source, $thumbnailPath, $mediumPath);
$size = $this->storePreviews($source, $thumbnailPath, $mediumPath);
} finally {
if ($decoded) {
@unlink($decoded);
Expand All @@ -243,15 +242,17 @@ private function processPhoto(Media $media, UploadedFile $file, string $basePath
'thumbnail_url' => $thumbnailPath,
'medium_url' => $mediumPath,
]);

return $size;
}

private function storePreviews(string $source, string $thumbnailPath, string $mediumPath): void
/** @return array{width: int, height: int} size after the EXIF orientation */
private function storePreviews(string $source, string $thumbnailPath, string $mediumPath): array
{
// Generate medium (1200px width)
$mediumImage = Image::decodePath($source)
->orient()
->scaleDown(width: 1200)
->encode(new JpegEncoder(quality: 85));
$image = Image::decodePath($source)->orient();
$size = ['width' => $image->width(), 'height' => $image->height()];
$mediumImage = $image->scaleDown(width: 1200)->encode(new JpegEncoder(quality: 85));

$this->storage->store($mediumPath, (string) $mediumImage);

Expand All @@ -262,6 +263,8 @@ private function storePreviews(string $source, string $thumbnailPath, string $me
->encode(new JpegEncoder(quality: 80));

$this->storage->store($thumbnailPath, (string) $thumbnailImage);

return $size;
}

// Run by ProcessVideoJob: make the HLS stream and set the moment's video_status to ready or failed.
Expand All @@ -286,6 +289,8 @@ public function processVideoMoment(Media $media): void
'medium_url' => $media->getRawMediumUrl(),
'hls_url' => $media->getRawHlsUrl(),
'duration' => $media->duration,
'width' => $media->width,
'height' => $media->height,
'video_status' => VideoStatus::Ready,
]);
}
Expand Down Expand Up @@ -334,7 +339,8 @@ private function processVideo(Media $media): void
->export()
->getFrameContents();

// Use GD to create resized versions
// Use GD to create resized versions. ffmpeg applies the rotation tag when it decodes (autorotate is on
// by default), so this frame and the width and height saved below are already the display size.
$sourceImage = imagecreatefromstring($frameContent) ?: throw new \RuntimeException('Cannot decode the video frame');
$origWidth = imagesx($sourceImage);
$origHeight = imagesy($sourceImage);
Expand Down
2 changes: 2 additions & 0 deletions kinlore-api/app/Services/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ public function formatMomentForSync(Moment $moment): array
'latitude' => $moment->latitude,
'longitude' => $moment->longitude,
'orientation' => $moment->orientation,
'width' => $moment->width,
'height' => $moment->height,
'duration' => $moment->duration,
'video_status' => $moment->video_status?->value,
'height_cm' => $moment->height_cm,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
// Display size of a photo or video, so the app can lay out the timeline before an image loads.
// On moments like orientation and duration: the API and sync read only moments. Filled for older rows by kinlore:media-dimensions.
public function up(): void
{
Schema::table('moments', function (Blueprint $table) {
$table->unsignedInteger('width')->nullable();
$table->unsignedInteger('height')->nullable();
});
}

public function down(): void
{
Schema::table('moments', fn (Blueprint $table) => $table->dropColumn(['width', 'height']));
}
};
Loading
Loading