Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dqbd committed Oct 12, 2023
1 parent 3c49b05 commit c75b0c3
Show file tree
Hide file tree
Showing 28 changed files with 82 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/components/RefreshImg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const RefreshImg = forwardRef<
useEffect(() => {
const interval = window.setInterval(
() => void setSession(Date.now()),
15 * 1000
15 * 1000,
)
return () => void window.clearInterval(interval)
}, [])
Expand Down
2 changes: 1 addition & 1 deletion src/components/Scrobber/ScrobberRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function ScrobberRange(props: {

const handleScrobberChange = (
from: dayjs.Dayjs | null,
to: dayjs.Dayjs | null
to: dayjs.Dayjs | null,
) => {
if (from != null && to != null) {
props.onChange({ from: from.valueOf(), to: to.valueOf() })
Expand Down
10 changes: 5 additions & 5 deletions src/components/Scrobber/ScrobberSlider.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function drawCanvas(
options: {
maxAge: number
bounds: { shift: [number, number] } | { pov: [dayjs.Dayjs, dayjs.Dayjs] }
}
},
) {
if (!canvas || !canvas.parentElement) return
const ctx = canvas.getContext("2d")
Expand Down Expand Up @@ -58,7 +58,7 @@ export function drawCanvas(
? now.add(playback.playing, "millisecond")
: playback.paused
).add(user, "millisecond"),
dateBounds
dateBounds,
)

const povStartOfDay = pov.startOf("day")
Expand All @@ -70,9 +70,9 @@ export function drawCanvas(
drawLine(
toCoordX(
pov,
dayjs.max(dateBounds?.min ?? pov, recordStart, povStartOfDay)
dayjs.max(dateBounds?.min ?? pov, recordStart, povStartOfDay),
),
toCoordX(pov, dayjs.min(dateBounds?.max ?? pov, recordEnd, povEndOfDay))
toCoordX(pov, dayjs.min(dateBounds?.max ?? pov, recordEnd, povEndOfDay)),
)

// draw markers
Expand Down Expand Up @@ -111,7 +111,7 @@ export function drawCanvas(
}

export function usePropsRef<Props extends Record<string, unknown>>(
props: Props
props: Props,
) {
const ref = useRef<Props>(props)

Expand Down
2 changes: 1 addition & 1 deletion src/npm-run-all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ declare module "npm-run-all" {
stdout?: Writable | null
stderr?: Writable | null
taskList?: string[] | null
}
},
): Promise<RunnerResult[]>
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/_error.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import NextErrorComponent, { ErrorProps } from "next/error"
import { loadServerConfig } from "shared/config"

type ErrorContext = Parameters<typeof NextErrorComponent["getInitialProps"]>[0]
type ErrorContext = Parameters<
(typeof NextErrorComponent)["getInitialProps"]
>[0]

function AppError({ statusCode }: ErrorProps) {
return <NextErrorComponent statusCode={statusCode} />
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/data/[folder]/[...file].ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import cors from "cors"

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
res: NextApiResponse,
) {
await runMiddleware(req, res, cors({ methods: ["GET", "HEAD"] }))

Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/data/[folder]/frame.jpg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import cors from "cors"

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
res: NextApiResponse,
) {
await runMiddleware(req, res, cors({ methods: ["GET", "HEAD"] }))

Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/data/[folder]/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const dbRef = createPersistentDatabase()

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
res: NextApiResponse,
) {
await runMiddleware(req, res, cors({ methods: ["POST", "HEAD"] }))

Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/data/[folder]/log/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function parseNumberQuery(value: string | string[] | undefined) {
}
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
res: NextApiResponse,
) {
await runMiddleware(req, res, cors({ methods: ["GET", "HEAD"] }))

Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/data/[folder]/log/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const RANGE = 10 * 60 // 20s

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
res: NextApiResponse,
) {
await runMiddleware(req, res, cors({ methods: ["GET", "HEAD"] }))

Expand All @@ -24,6 +24,6 @@ export default async function handler(
const timestampSec = Math.floor((Date.now() - shift * 1000) / 1000)

res.send(
await db.logRange(folder, timestampSec - RANGE, timestampSec + RANGE)
await db.logRange(folder, timestampSec - RANGE, timestampSec + RANGE),
)
}
4 changes: 2 additions & 2 deletions src/pages/api/data/[folder]/slice.m3u8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function parseNumberQuery(value: string | string[] | undefined) {
}
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
res: NextApiResponse,
) {
await runMiddleware(req, res, cors({ methods: ["GET", "HEAD"] }))

Expand Down Expand Up @@ -44,7 +44,7 @@ export default async function handler(

const items = (await db.seek(folder, fromSec, toSec))
.map((item) =>
Segment.parseSegment(item.path, item.targetDuration, item.pdt)
Segment.parseSegment(item.path, item.targetDuration, item.pdt),
)
.filter(isSegment)

Expand Down
6 changes: 3 additions & 3 deletions src/pages/api/data/[folder]/stream.m3u8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const dbRef = createPersistentDatabase()

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
res: NextApiResponse,
) {
await runMiddleware(req, res, cors({ methods: ["GET", "HEAD"] }))

Expand All @@ -35,7 +35,7 @@ export default async function handler(
.map((line) =>
line.startsWith(baseFolder)
? path.relative(path.join(baseFolder, folder), line)
: line
: line,
)
.join("\n")

Expand All @@ -44,7 +44,7 @@ export default async function handler(
const timestampSec = Math.floor((Date.now() - shift * 1000) / 1000)
const segments = (await db.seekFrom(folder, timestampSec))
.map((item) =>
Segment.parseSegment(item.path, item.targetDuration, item.pdt)
Segment.parseSegment(item.path, item.targetDuration, item.pdt),
)
.filter(isSegment)

Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cors from "cors"

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
res: NextApiResponse,
) {
await runMiddleware(req, res, cors({ methods: ["GET", "HEAD"] }))

Expand Down
6 changes: 3 additions & 3 deletions src/server/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function cleanup() {
now.getFullYear(),
now.getMonth(),
now.getDate(),
now.getHours()
now.getHours(),
).valueOf()

const cleanupThreshold = nowTime - config.maxAge * 1000
Expand All @@ -38,8 +38,8 @@ async function cleanup() {

await Promise.all(
folders.map((target) =>
fs.promises.rm(target, { recursive: true, force: true })
)
fs.promises.rm(target, { recursive: true, force: true }),
),
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const main = async () => {

logger.info("- Reading folder list")
const toInsert = (await fs.promises.readdir(folderTarget)).filter(
(folder) => folder.indexOf("_") >= 0
(folder) => folder.indexOf("_") >= 0,
)

for (const target of toInsert) {
Expand Down
6 changes: 3 additions & 3 deletions src/server/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function sync() {
cameraKey,
manifest.targetDuration,
relative,
manifest.pdts[index]
manifest.pdts[index],
)
}
}
Expand All @@ -74,12 +74,12 @@ async function sync() {
chokidar
.watch(
Object.keys(config.targets).map((cameraKey) =>
path.resolve(baseFolder, cameraKey, MANIFEST)
path.resolve(baseFolder, cameraKey, MANIFEST),
),
// use polling instead, as sometimes chokidar
// just stops detecting new changes
// this might not work...
{ usePolling: true }
{ usePolling: true },
)
.on("add", handleChange)
.on("change", handleChange)
Expand Down
4 changes: 2 additions & 2 deletions src/server/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function staleFrameLoop() {

function trigger() {
logger.error(
`Stale FFMPEG (frame=${lastFrameCount}), no new frames received`
`Stale FFMPEG (frame=${lastFrameCount}), no new frames received`,
)
process.exit(3)
}
Expand Down Expand Up @@ -104,7 +104,7 @@ async function launchWorker(cameraKey: string | undefined) {
`-hls_flags program_date_time+second_level_segment_index+second_level_segment_duration`,
`-hls_segment_filename ${path.resolve(
cameraFolder,
"%Y_%m_%d_%H/sg_%s_%%d_%%t.ts"
"%Y_%m_%d_%H/sg_%s_%%d_%%t.ts",
)}`,
])

Expand Down
10 changes: 5 additions & 5 deletions src/shared/clocksync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function setSystemTime(
credential: { username: string; password: string },
ip: string,
port = 34567,
time?: Date
time?: Date,
) {
return new Promise<void>((resolve, reject) => {
const socket = new net.Socket()
Expand All @@ -103,8 +103,8 @@ export function setSystemTime(
packetBuilder(
getTimePacket(sessionId, time),
types.SET_TIME,
sessionId
)
sessionId,
),
)
break
}
Expand Down Expand Up @@ -137,8 +137,8 @@ export function setSystemTime(
socket.write(
packetBuilder(
getLoginPacket(credential.username, credential.password),
types.AUTH
)
types.AUTH,
),
)
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ConfigDto = z.object({
z.object({
name: z.string(),
source: z.string(),
})
}),
),
})

Expand Down Expand Up @@ -61,7 +61,7 @@ export async function loadServerConfig() {
const config = JSON.parse(
env.CONFIG_BASE64 != null
? Buffer.from(env.CONFIG_BASE64, "base64").toString("utf-8")
: await fs.readFile(path.resolve(env.CONFIG_PATH), { encoding: "utf-8" })
: await fs.readFile(path.resolve(env.CONFIG_PATH), { encoding: "utf-8" }),
)

return {
Expand Down
14 changes: 7 additions & 7 deletions src/shared/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ export class Database {
camera: string,
keyBase: string,
filenames: string[],
chunkSize = 256
chunkSize = 256,
) {
const inferTargetDuration = Math.floor(
filenames
.map((i) => Segment.parseSegment(i, -1, null)?.getExtInf())
.filter((i): i is string => i != null)
.map((i) => Number.parseFloat(i))
.filter((i) => !Number.isNaN(i))
.reduce((min, i) => Math.min(min, i), Infinity)
.reduce((min, i) => Math.min(min, i), Infinity),
)

const segments = filenames.reduce<CameraTable[]>((memo, filename) => {
Expand All @@ -99,12 +99,12 @@ export class Database {
camera: string,
targetDuration: number,
path: string,
pdt: string | null
pdt: string | null,
) {
const segment = Segment.parseSegment(
fsPath.basename(path),
targetDuration,
pdt ? new Date(Date.parse(pdt)) : null
pdt ? new Date(Date.parse(pdt)) : null,
)

if (!segment) return null
Expand Down Expand Up @@ -149,7 +149,7 @@ export class Database {
async seekFrom(
camera: string,
fromSec: number,
limit = 5
limit = 5,
): Promise<CameraTable[]> {
const from = new Date(fromSec * 1000)

Expand All @@ -161,7 +161,7 @@ export class Database {
.from<CameraTable>(camera)
.where("timestamp", "<=", from)
.orderBy("timestamp", "desc")
.limit(1)
.limit(1),
)
.with(
"remaining",
Expand All @@ -170,7 +170,7 @@ export class Database {
.from<CameraTable>(camera)
.where("timestamp", ">", from)
.orderBy("timestamp", "asc")
.limit(limit - 1)
.limit(limit - 1),
)
.select("*")
.from("inclusive")
Expand Down

0 comments on commit c75b0c3

Please sign in to comment.