Something went wrong. Try again.
Synapse is a study workspace. Organize courses read and annotate the material, train with generated exercises and watch your progress forked from denishovart.com/synapse
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031import { Body, Controller, Get, Post, Query } from '@nestjs/common';import type { PublicUser } from '../domain/models';import { CurrentUser } from '../auth/auth.decorators';import { SyncService } from '../application/sync.service';import { PushUpdatesDto, UpdatesQueryDto } from './dto/sync.dto';
const ownerOf = (u: PublicUser | undefined): string | null => u?.id ?? null;
// Local-first sync peer: clients pull update blobs they have not seen (by// per-doc cursor) and push the ones they created. Payloads are opaque Loro// updates; the server only stores and orders them.@Controller('api/sync')export class SyncController { constructor(private readonly service: SyncService) {}
@Get('manifest') async manifest(@CurrentUser() user?: PublicUser) { return { docs: await this.service.manifest(ownerOf(user)) }; }
@Get('updates') updates(@Query() query: UpdatesQueryDto, @CurrentUser() user?: PublicUser) { return this.service.updatesSince(ownerOf(user), query.doc_id!, query.after_seq ?? 0); }
@Post('updates') push(@Body() dto: PushUpdatesDto, @CurrentUser() user?: PublicUser) { return this.service.push(ownerOf(user), dto.doc_id!, dto.updates ?? [], dto.device_id ?? null); }}