[BREAKING!]: 서버 재작업 #16

Merged
monoid merged 3 commits from dev into main 2024-10-09 00:18:57 +09:00
8 changed files with 19 additions and 19 deletions
Showing only changes of commit 0bcfc9d74a - Show all commits

View File

@ -1,6 +1,6 @@
import { randomBytes } from "node:crypto"; import { randomBytes } from "node:crypto";
import { existsSync, readFileSync, writeFileSync } from "node:fs"; import { existsSync, readFileSync, writeFileSync } from "node:fs";
import type { Permission } from "./permission/permission"; import type { Permission } from "./permission/permission.ts";
export interface SettingConfig { export interface SettingConfig {
/** /**

View File

@ -1,6 +1,4 @@
import { existsSync } from "node:fs"; import { getKysely } from "./db/kysely.ts";
import { get_setting } from "./SettingConfig";
import { getKysely } from "./db/kysely";
export async function connectDB() { export async function connectDB() {
const kysely = getKysely(); const kysely = getKysely();

View File

@ -1,4 +1,4 @@
import type { ContentFile } from "../content/mod"; import type { ContentFile } from "../content/mod.ts";
export class ContentList { export class ContentList {
/** path map */ /** path map */

View File

@ -1,7 +1,7 @@
import asyncPool from "tiny-async-pool"; import asyncPool from "tiny-async-pool";
import type { DocumentAccessor } from "../model/doc"; import type { DocumentAccessor } from "../model/doc.ts";
import { ContentDiffHandler } from "./content_handler"; import { ContentDiffHandler } from "./content_handler.ts";
import type { IDiffWatcher } from "./watcher"; import type { IDiffWatcher } from "./watcher.ts";
export class DiffManager { export class DiffManager {
watching: { [content_type: string]: ContentDiffHandler }; watching: { [content_type: string]: ContentDiffHandler };

View File

@ -1,9 +1,9 @@
import type Koa from "koa"; import type Koa from "koa";
import Router from "koa-router"; import Router from "koa-router";
import type { ContentFile } from "../content/mod"; import type { ContentFile } from "../content/mod.ts";
import { AdminOnlyMiddleware } from "../permission/permission"; import { AdminOnlyMiddleware } from "../permission/permission.ts";
import { sendError } from "../route/error_handler"; import { sendError } from "../route/error_handler.ts";
import type { DiffManager } from "./diff"; import type { DiffManager } from "./diff.ts";
function content_file_to_return(x: ContentFile) { function content_file_to_return(x: ContentFile) {
return { path: x.path, type: x.type }; return { path: x.path, type: x.type };

View File

@ -2,7 +2,7 @@ import type event from "node:events";
import { FSWatcher, watch } from "node:fs"; import { FSWatcher, watch } from "node:fs";
import { promises } from "node:fs"; import { promises } from "node:fs";
import { join } from "node:path"; import { join } from "node:path";
import type { DocumentAccessor } from "../model/doc"; import type { DocumentAccessor } from "../model/doc.ts";
const readdir = promises.readdir; const readdir = promises.readdir;

View File

@ -1,6 +1,6 @@
import type Koa from "koa"; import type Koa from "koa";
import type { UserState } from "../login"; import type { UserState } from "../login.ts";
import { sendError } from "../route/error_handler"; import { sendError } from "../route/error_handler.ts";
export enum Permission { export enum Permission {
// ======== // ========

View File

@ -24,19 +24,21 @@ export async function oshash(
} }
// read first and last chunk // read first and last chunk
const firstChunk = Buffer.alloc(chunkSize); const firstChunk = new Uint8Array(chunkSize);
await fd.read(firstChunk, 0, chunkSize, 0); await fd.read(firstChunk, 0, chunkSize, 0);
const lastChunk = Buffer.alloc(chunkSize); const lastChunk = new Uint8Array(chunkSize);
await fd.read(lastChunk, 0, chunkSize, st.size - chunkSize); await fd.read(lastChunk, 0, chunkSize, st.size - chunkSize);
// iterate over first and last chunk. // iterate over first and last chunk.
// for each uint64_t, add it to the hash. // for each uint64_t, add it to the hash.
const firstChunkView = new DataView(firstChunk.buffer);
for (let i = 0; i < chunkSize; i += 8){ for (let i = 0; i < chunkSize; i += 8){
hash += firstChunk.readBigUInt64LE(i); hash += firstChunkView.getBigUint64(i, true);
// prevent overflow // prevent overflow
hash = (hash & 0xFFFFFFFFFFFFFFFFn); hash = (hash & 0xFFFFFFFFFFFFFFFFn);
} }
const lastChunkView = new DataView(lastChunk.buffer);
for (let i = 0; i < chunkSize; i += 8){ for (let i = 0; i < chunkSize; i += 8){
hash += lastChunk.readBigUInt64LE(i); hash += lastChunkView.getBigUint64(i, true);
// prevent overflow // prevent overflow
hash = (hash & 0xFFFFFFFFFFFFFFFFn); hash = (hash & 0xFFFFFFFFFFFFFFFFn);
} }