mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-26 18:51:50 +02:00
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { getJSON } from '../../../infrastructure/fetch-json'
|
|
import { FileDiff } from './types/file'
|
|
import { Update } from './types/update'
|
|
import { DocDiffResponse } from './types/doc'
|
|
|
|
const BATCH_SIZE = 10
|
|
|
|
export function fetchUpdates(projectId: string, before?: number) {
|
|
const queryParams: Record<string, string> = {
|
|
min_count: BATCH_SIZE.toString(),
|
|
}
|
|
|
|
if (before != null) {
|
|
queryParams.before = before.toString()
|
|
}
|
|
|
|
const queryParamsSerialized = new URLSearchParams(queryParams).toString()
|
|
const updatesURL = `/project/${projectId}/updates?${queryParamsSerialized}`
|
|
return getJSON<{ updates: Update[] }>(updatesURL)
|
|
}
|
|
|
|
export function diffFiles(projectId: string, fromV: number, toV: number) {
|
|
const queryParams: Record<string, string> = {
|
|
from: fromV.toString(),
|
|
to: toV.toString(),
|
|
}
|
|
const queryParamsSerialized = new URLSearchParams(queryParams).toString()
|
|
const diffUrl = `/project/${projectId}/filetree/diff?${queryParamsSerialized}`
|
|
return getJSON<{ diff: FileDiff[] }>(diffUrl)
|
|
}
|
|
|
|
export function diffDoc(
|
|
projectId: string,
|
|
fromV: number,
|
|
toV: number,
|
|
pathname: string
|
|
) {
|
|
const queryParams: Record<string, string> = {
|
|
from: fromV.toString(),
|
|
to: toV.toString(),
|
|
pathname,
|
|
}
|
|
const queryParamsSerialized = new URLSearchParams(queryParams).toString()
|
|
const diffUrl = `/project/${projectId}/diff?${queryParamsSerialized}`
|
|
return getJSON<DocDiffResponse>(diffUrl)
|
|
}
|