Skip to content

Commit

Permalink
UBERF-4729: Fix front service (#4260)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo authored Dec 25, 2023
1 parent 8d7d11a commit b522334
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 20 deletions.
26 changes: 24 additions & 2 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions server/backup/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,10 @@ export async function restore (
})
})
const unzip = createGunzip()

readStream.on('end', () => {
readStream.destroy()
})
readStream.pipe(unzip)
unzip.pipe(ex)

Expand Down
1 change: 1 addition & 0 deletions server/core/src/indexer/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class ContentRetrievalStage implements FullTextPipelineStage {
{},
async () => await this.contentAdapter.content(ref, contentType, readable)
)
readable?.destroy()

textContent = textContent
.split(/ +|\t+|\f+/)
Expand Down
6 changes: 4 additions & 2 deletions server/front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"@types/jest": "^29.5.5",
"prettier-plugin-svelte": "^3.1.0"
"prettier-plugin-svelte": "^3.1.0",
"@types/morgan": "~1.9.9"
},
"dependencies": {
"@hcengineering/core": "^0.6.28",
Expand All @@ -52,6 +53,7 @@
"body-parser": "~1.19.1",
"compression": "~1.7.4",
"sharp": "~0.32.0",
"@hcengineering/minio": "^0.6.0"
"@hcengineering/minio": "^0.6.0",
"morgan": "^1.10.0"
}
}
47 changes: 32 additions & 15 deletions server/front/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import https from 'https'
import { join, resolve } from 'path'
import sharp from 'sharp'
import { v4 as uuid } from 'uuid'
import morgan from 'morgan'

async function minioUpload (minio: MinioService, workspace: WorkspaceId, file: UploadedFile): Promise<string> {
const id = uuid()
Expand Down Expand Up @@ -85,7 +86,14 @@ async function getFileRange (
'Content-Range': `bytes ${start}-${end}/${size}`,
'Accept-Ranges': 'bytes',
'Content-Length': end - start + 1,
'Content-Type': stat.metaData['content-type']
'Content-Type': stat.metaData['content-type'],
Etag: stat.etag,
'Last-Modified': stat.lastModified.toISOString()
})

dataStream.on('end', () => {
dataStream.destroy()
res.end()
})

dataStream.pipe(res)
Expand All @@ -100,19 +108,18 @@ async function getFile (client: MinioService, workspace: WorkspaceId, uuid: stri

try {
const dataStream = await client.get(workspace, uuid)
res.status(200)
res.set('Cache-Control', 'max-age=7d')

const contentType = stat.metaData['content-type']
if (contentType !== undefined) {
res.setHeader('Content-Type', contentType)
}
res.writeHead(200, {
'Content-Type': stat.metaData['content-type'],
Etag: stat.etag,
'Last-Modified': stat.lastModified.toISOString()
})

dataStream.on('data', function (chunk) {
res.write(chunk)
})
dataStream.on('end', function () {
res.end()
dataStream.destroy()
})
dataStream.on('error', function (err) {
console.log(err)
Expand Down Expand Up @@ -169,6 +176,8 @@ export function start (
app.use(bp.json())
app.use(bp.urlencoded({ extended: true }))

app.use(morgan('combined'))

// eslint-disable-next-line @typescript-eslint/no-misused-promises
app.get('/config.json', async (req, res) => {
res.status(200)
Expand Down Expand Up @@ -215,11 +224,14 @@ export function start (

const fileSize = stat.size

res.writeHead(200, {
'accept-ranges': 'bytes',
'content-length': fileSize,
Etag: stat.etag,
'Last-Modified': stat.lastModified.toISOString()
})
res.status(200)

res.setHeader('accept-ranges', 'bytes')
res.setHeader('content-length', fileSize)

res.end()
} catch (error) {
console.log(error)
Expand All @@ -229,7 +241,6 @@ export function start (

const filesHandler = async (req: any, res: Response): Promise<void> => {
try {
console.log(req.headers)
const cookies = ((req?.headers?.cookie as string) ?? '').split(';').map((it) => it.trim().split('='))

const token = cookies.find((it) => it[0] === 'presentation-metadata-Token')?.[1]
Expand Down Expand Up @@ -262,8 +273,12 @@ export function start (
} else {
await getFile(config.minio, payload.workspace, uuid, res)
}
} catch (error) {
console.log(error)
} catch (error: any) {
if (error?.code === 'NoSuchKey' || error?.code === 'NotFound') {
console.log('No such key', req.query.file)
} else {
console.log(error)
}
res.status(500).send()
}
}
Expand Down Expand Up @@ -565,7 +580,9 @@ async function getResizeID (
const d = await config.minio.stat(payload.workspace, sizeId)
hasSmall = d !== undefined && d.size > 0
} catch (err: any) {
console.error(err)
if (err.code !== 'NotFound') {
console.error(err)
}
}
if (hasSmall) {
// We have cached small document, let's proceed with it.
Expand Down
2 changes: 2 additions & 0 deletions server/minio/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class MinioService {
}
})
list.on('end', () => {
list.destroy()
resolve(null)
})
})
Expand Down Expand Up @@ -111,6 +112,7 @@ export class MinioService {
})

data.on('end', () => {
data.destroy()
resolve(null)
})
})
Expand Down
4 changes: 4 additions & 0 deletions tests/sanity/storage.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"name": "#platform.notification.logging",
"value": "false"
},
{
"name": "#platform.notification.timeout",
"value": "0"
},
{
"name": "#platform.lazy.loading",
"value": "false"
Expand Down
4 changes: 4 additions & 0 deletions tests/sanity/storageSecond-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"name": "#platform.notification.timeout",
"value": "0"
},
{
"name": "#platform.notification.timeout",
"value": "0"
},
{
"name": "#platform.testing.enabled",
"value": "true"
Expand Down
2 changes: 1 addition & 1 deletion tests/sanity/tests/model/tracker/issues-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class IssuesPage extends CommonTrackerPage {
)
}

async createNewIssue (data: NewIssue, closeNotification: boolean = true): Promise<void> {
async createNewIssue (data: NewIssue, closeNotification: boolean = false): Promise<void> {
await this.buttonCreateNewIssue.click()
await this.fillNewIssueForm(data)
await this.buttonCreateIssue.click()
Expand Down

0 comments on commit b522334

Please sign in to comment.