-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5ec44a
commit c03f714
Showing
11 changed files
with
163 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,12 @@ | ||
export const b64encode = (arrayBuffer: ArrayBuffer) => { | ||
const buffer = Buffer.from(arrayBuffer) | ||
const base64String = buffer.toString('base64') | ||
|
||
// export const b64encode = (buf: ArrayBuffer) => { | ||
// return btoa(String.fromCharCode(...new Uint8Array(buf))) | ||
// } | ||
|
||
export const b64encode = (buffer: ArrayBuffer) => { | ||
let binary = '' | ||
const bytes = new Uint8Array(buffer) | ||
const len = bytes.byteLength | ||
for (let i = 0; i < len; i++) { | ||
binary += String.fromCharCode(bytes[i]!) | ||
} | ||
|
||
return window.btoa(binary) | ||
return base64String | ||
} | ||
|
||
// export const b64decode = (str: string) => { | ||
// const binary_string = window.atob(str) | ||
// const len = binary_string.length | ||
// const bytes = new Uint8Array(new ArrayBuffer(len)) | ||
// for (let i = 0; i < len; i++) { | ||
// bytes[i] = binary_string.charCodeAt(i) | ||
// } | ||
|
||
// return bytes | ||
// } | ||
|
||
export const b64decode = (base64: string) => { | ||
const buffer = Buffer.from(base64, 'base64') | ||
|
||
return new Uint8Array(buffer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { b64encode } from './base64' | ||
import { | ||
b64toStream, | ||
compressStream, | ||
decompressStream, | ||
JSONtoStream, | ||
responseToBuffer | ||
} from './compress' | ||
|
||
export const compressContent = async (content: Record<string, unknown>) => { | ||
const compressedStream = await compressStream(JSONtoStream(content)) | ||
const compressedBuffer = await responseToBuffer(compressedStream) | ||
|
||
return b64encode(compressedBuffer) | ||
} | ||
|
||
export const decompressContent = (base64: string): Promise<Record<string, unknown>> => { | ||
const contentResponse = decompressStream(b64toStream(base64)) | ||
|
||
return contentResponse.json() as Promise<Record<string, unknown>> | ||
} |
42 changes: 0 additions & 42 deletions
42
src/server/api/whiteboard/usecases/find-public-whiteboard.ts
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/server/api/whiteboard/usecases/find-whiteboard-content.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { and, eq,type SQL } from 'drizzle-orm' | ||
import { type PostgresJsDatabase } from 'drizzle-orm/postgres-js' | ||
import { type z } from 'zod' | ||
|
||
import { type SearchWhitheboard } from '@/dtos/whiteboard-dtos' | ||
import { compressContent } from '@/lib/compress-whiteboard' | ||
import type * as schema from '@/server/db/schema' | ||
import { whiteboards } from '@/server/db/schema' | ||
import { NotFound } from '@/server/exceptions/not-found' | ||
|
||
|
||
type Options = z.infer<typeof SearchWhitheboard> | ||
|
||
const findWhiteboardContent = async (db: PostgresJsDatabase<typeof schema>, options: Options) => { | ||
const { id, isPublic } = options | ||
|
||
let baseFilter = eq(whiteboards.id, id) | ||
|
||
if (isPublic !== undefined){ | ||
baseFilter = and(baseFilter, eq(whiteboards.isPublic, isPublic)) as SQL<typeof schema> | ||
} | ||
|
||
const currentWhiteboard = await db.query.whiteboards.findFirst({ | ||
where: baseFilter, | ||
with: { | ||
createdBy: { | ||
columns: { | ||
email: false, | ||
emailVerified: false, | ||
} | ||
}, | ||
} | ||
}) | ||
|
||
if (!currentWhiteboard){ | ||
throw new NotFound('Whiteboard not found') | ||
} | ||
|
||
const compressedRawContent = await compressContent(currentWhiteboard.content as Record<string, unknown>) | ||
|
||
return { | ||
id: currentWhiteboard.id, | ||
name: currentWhiteboard.name, | ||
compressedRawContent, | ||
description: currentWhiteboard.description, | ||
previewUrl: currentWhiteboard.previewUrl, | ||
createdBy: currentWhiteboard.createdBy, | ||
} | ||
} | ||
|
||
export default findWhiteboardContent |
37 changes: 37 additions & 0 deletions
37
src/server/api/whiteboard/usecases/find-whiteboard-info.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { and, eq,type SQL } from 'drizzle-orm' | ||
import { type PostgresJsDatabase } from 'drizzle-orm/postgres-js' | ||
import { type z } from 'zod' | ||
|
||
import { type SearchWhitheboard } from '@/dtos/whiteboard-dtos' | ||
import type * as schema from '@/server/db/schema' | ||
import { whiteboards } from '@/server/db/schema' | ||
import { NotFound } from '@/server/exceptions/not-found' | ||
|
||
|
||
type Options = z.infer<typeof SearchWhitheboard> | ||
|
||
const findWhiteboardInfo = async (db: PostgresJsDatabase<typeof schema>, options: Options) => { | ||
const { id, isPublic } = options | ||
|
||
let baseFilter = eq(whiteboards.id, id) | ||
|
||
if (isPublic !== undefined){ | ||
baseFilter = and(baseFilter, eq(whiteboards.isPublic, isPublic)) as SQL<typeof schema> | ||
} | ||
|
||
const currentWhiteboard = await db.query.whiteboards.findFirst({ | ||
where: baseFilter, | ||
columns: { | ||
content: false, | ||
} | ||
}) | ||
|
||
if (!currentWhiteboard){ | ||
throw new NotFound('Whiteboard not found') | ||
} | ||
|
||
|
||
return currentWhiteboard | ||
} | ||
|
||
export default findWhiteboardInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters