Remove Upload package (#565)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2021-12-09 16:10:54 +07:00 committed by GitHub
parent e3d9919c3e
commit 34d1b7a5a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 0 additions and 508 deletions

View File

@ -89,7 +89,6 @@ specifiers:
'@rush-temp/theme': file:./projects/theme.tgz '@rush-temp/theme': file:./projects/theme.tgz
'@rush-temp/tool': file:./projects/tool.tgz '@rush-temp/tool': file:./projects/tool.tgz
'@rush-temp/ui': file:./projects/ui.tgz '@rush-temp/ui': file:./projects/ui.tgz
'@rush-temp/upload': file:./projects/upload.tgz
'@rush-temp/view': file:./projects/view.tgz '@rush-temp/view': file:./projects/view.tgz
'@rush-temp/view-assets': file:./projects/view-assets.tgz '@rush-temp/view-assets': file:./projects/view-assets.tgz
'@rush-temp/view-resources': file:./projects/view-resources.tgz '@rush-temp/view-resources': file:./projects/view-resources.tgz
@ -252,7 +251,6 @@ dependencies:
'@rush-temp/theme': file:projects/theme.tgz_476f694f64637160ae71e12ff57815b9 '@rush-temp/theme': file:projects/theme.tgz_476f694f64637160ae71e12ff57815b9
'@rush-temp/tool': file:projects/tool.tgz '@rush-temp/tool': file:projects/tool.tgz
'@rush-temp/ui': file:projects/ui.tgz_476f694f64637160ae71e12ff57815b9 '@rush-temp/ui': file:projects/ui.tgz_476f694f64637160ae71e12ff57815b9
'@rush-temp/upload': file:projects/upload.tgz
'@rush-temp/view': file:projects/view.tgz '@rush-temp/view': file:projects/view.tgz
'@rush-temp/view-assets': file:projects/view-assets.tgz '@rush-temp/view-assets': file:projects/view-assets.tgz
'@rush-temp/view-resources': file:projects/view-resources.tgz_476f694f64637160ae71e12ff57815b9 '@rush-temp/view-resources': file:projects/view-resources.tgz_476f694f64637160ae71e12ff57815b9
@ -11517,42 +11515,6 @@ packages:
- supports-color - supports-color
dev: false dev: false
file:projects/upload.tgz:
resolution: {integrity: sha512-WaGQUnqC0+TnVK024k91eTALA6ObkexINzJoxr5qZp5aPBJQ/UzP9Qyy2qcy5U7sFpUzUcADf25+r/LnYw1lfQ==, tarball: file:projects/upload.tgz}
name: '@rush-temp/upload'
version: 0.0.0
dependencies:
'@rushstack/heft': 0.41.1
'@types/cors': 2.8.12
'@types/express': 4.17.13
'@types/express-fileupload': 1.1.7
'@types/heft-jest': 1.0.2
'@types/minio': 7.0.10
'@types/node': 16.10.3
'@types/uuid': 8.3.1
'@typescript-eslint/eslint-plugin': 5.4.0_87dbf04088b125598d0271706532eaf3
'@typescript-eslint/parser': 5.4.0_eslint@7.32.0+typescript@4.4.3
cors: 2.8.5
esbuild: 0.12.29
eslint: 7.32.0
eslint-config-standard-with-typescript: 21.0.1_05a8ea1454e6ca4c9f98b94b8f3abf9c
eslint-plugin-import: 2.25.3_eslint@7.32.0
eslint-plugin-node: 11.1.0_eslint@7.32.0
eslint-plugin-promise: 5.1.1_eslint@7.32.0
express: 4.17.1
express-fileupload: 1.2.1
jwt-simple: 0.5.6
minio: 7.0.19
prettier: 2.4.1
ts-node: 10.2.1_8304ecd715830f7c190b4d1dea90b100
typescript: 4.4.3
uuid: 8.3.2
transitivePeerDependencies:
- '@swc/core'
- '@swc/wasm'
- supports-color
dev: false
file:projects/view-assets.tgz: file:projects/view-assets.tgz:
resolution: {integrity: sha512-dUheCsjUx+oFp4fsGElxwZoCjEUjqd+3jx7p6pnPyO2xA3uiw3F4Jqoj4P6Lu4yw2CavQKbGQIwOAkmcxPvUAg==, tarball: file:projects/view-assets.tgz} resolution: {integrity: sha512-dUheCsjUx+oFp4fsGElxwZoCjEUjqd+3jx7p6pnPyO2xA3uiw3F4Jqoj4P6Lu4yw2CavQKbGQIwOAkmcxPvUAg==, tarball: file:projects/view-assets.tgz}
name: '@rush-temp/view-assets' name: '@rush-temp/view-assets'

View File

@ -726,11 +726,6 @@
"projectFolder": "dev/account", "projectFolder": "dev/account",
"shouldPublish": true "shouldPublish": true
}, },
{
"packageName": "@anticrm/upload",
"projectFolder": "server/upload",
"shouldPublish": true
},
{ {
"packageName": "@anticrm/server-chunter-resources", "packageName": "@anticrm/server-chunter-resources",
"projectFolder": "server/chunter-resources", "projectFolder": "server/chunter-resources",

View File

@ -1,7 +0,0 @@
module.exports = {
extends: ['./node_modules/@anticrm/platform-rig/profiles/default/config/eslint.config.json'],
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json'
}
}

View File

@ -1,4 +0,0 @@
*
!/lib/**
!CHANGELOG.md
/lib/**/__tests__/

View File

@ -1,9 +0,0 @@
FROM node
WORKDIR /usr/src/app
COPY bundle.js ./
EXPOSE 3000
CMD [ "node", "bundle.js" ]

View File

@ -1,20 +0,0 @@
#!/bin/bash
#
# Copyright © 2020, 2021 Anticrm Platform Contributors.
# Copyright © 2021 Hardcore Engineering Inc.
#
# Licensed under the Eclipse Public License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may
# obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
rushx bundle
rushx docker:build
rushx docker:push

View File

@ -1,18 +0,0 @@
// The "rig.json" file directs tools to look for their config files in an external package.
// Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
{
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
/**
* (Required) The name of the rig package to inherit from.
* It should be an NPM package name with the "-rig" suffix.
*/
"rigPackageName": "@anticrm/platform-rig"
/**
* (Optional) Selects a config profile from the rig package. The name must consist of
* lowercase alphanumeric words separated by hyphens, for example "sample-profile".
* If omitted, then the "default" profile will be used."
*/
// "rigProfile": "your-profile-name"
}

View File

@ -1,43 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: upload
spec:
replicas: 1
selector:
matchLabels:
app: upload
template:
metadata:
labels:
app: upload
spec:
containers:
- name: app
image: anticrm/upload
ports:
- containerPort: 3000
imagePullPolicy: Always
env:
- name: TRANSACTOR_URL
value: ws://transactor/
- name: ELASTIC_URL
valueFrom:
secretKeyRef:
name: elastic
key: url
- name: MINIO_ENDPOINT
valueFrom:
secretKeyRef:
name: minio
key: endpoint
- name: MINIO_ACCESS_KEY
valueFrom:
secretKeyRef:
name: minio
key: accessKey
- name: MINIO_SECRET_KEY
valueFrom:
secretKeyRef:
name: minio
key: secretKey

View File

@ -1,24 +0,0 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/issuer: "letsencrypt-prod"
name: upload-ingress
spec:
tls:
- hosts:
- upload.hc.engineering
secretName: upload-tls
rules:
- host: upload.hc.engineering
http:
paths:
- backend:
service:
name: upload
port:
number: 80
path: /
pathType: Prefix

View File

@ -1,10 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: upload
spec:
selector:
app: upload
ports:
- port: 80
targetPort: 3000

View File

@ -1,54 +0,0 @@
{
"name": "@anticrm/upload",
"version": "0.6.1",
"main": "lib/index.js",
"author": "Anticrm Platform Contributors",
"license": "EPL-2.0",
"scripts": {
"start": "ts-node src/__start.ts",
"build": "heft build",
"build:watch": "tsc",
"lint:fix": "eslint --fix src",
"bundle": "esbuild src/__start.ts --bundle --platform=node > bundle.js",
"docker:build": "docker build -t anticrm/upload .",
"docker:push": "docker push anticrm/upload",
"lint": "eslint src",
"format": "prettier --write src && eslint --fix src"
},
"devDependencies": {
"@anticrm/platform-rig": "~0.6.0",
"@types/heft-jest": "^1.0.2",
"@types/node": "^16.4.10",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-promise": "^5.1.1",
"eslint-plugin-node": "^11.1.0",
"eslint": "^7.32.0",
"@types/express": "^4.17.13",
"ts-node": "^10.2.0",
"@types/express-fileupload": "^1.1.7",
"@types/uuid": "^8.3.1",
"@types/cors": "^2.8.12",
"@types/minio": "^7.0.10",
"esbuild": "^0.12.24",
"@typescript-eslint/parser": "^5.4.0",
"eslint-config-standard-with-typescript": "^21.0.1",
"prettier": "^2.4.1",
"@rushstack/heft": "^0.41.1",
"typescript": "^4.3.5"
},
"dependencies": {
"@anticrm/platform": "~0.6.5",
"express": "^4.17.1",
"express-fileupload": "^1.2.1",
"uuid": "^8.3.2",
"cors": "^2.8.5",
"@anticrm/elastic": "~0.6.0",
"jwt-simple": "^0.5.6",
"@anticrm/server-core": "~0.6.1",
"@anticrm/attachment": "~0.6.0",
"@anticrm/core": "~0.6.11",
"@anticrm/contrib": "~0.6.0",
"minio": "^7.0.19"
}
}

View File

@ -1,66 +0,0 @@
//
// Copyright © 2020, 2021 Anticrm Platform Contributors.
// Copyright © 2021 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
import { start } from './app'
import { Client } from 'minio'
const url = process.env.TRANSACTOR_URL
if (url === undefined) {
console.error('please provide transactor url')
process.exit(1)
}
const elasticUrl = process.env.ELASTIC_URL
if (elasticUrl === undefined) {
console.error('please provide elastic url')
process.exit(1)
}
const minioEndpoint = process.env.MINIO_ENDPOINT
if (minioEndpoint === undefined) {
console.error('please provide minio endpoint')
process.exit(1)
}
const minioAccessKey = process.env.MINIO_ACCESS_KEY
if (minioAccessKey === undefined) {
console.error('please provide minio access key')
process.exit(1)
}
const minioSecretKey = process.env.MINIO_SECRET_KEY
if (minioSecretKey === undefined) {
console.error('please provide minio secret key')
process.exit(1)
}
const minio = new Client({
endPoint: minioEndpoint,
port: 9000,
useSSL: false,
accessKey: minioAccessKey,
secretKey: minioSecretKey
})
const shutdown = start(url, elasticUrl, minio, 3000)
const close = (): void => {
shutdown()
process.exit(0)
}
process.on('SIGINT', close)
process.on('SIGTERM', close)
process.on('exit', close)

View File

@ -1,184 +0,0 @@
//
// Copyright © 2020, 2021 Anticrm Platform Contributors.
// Copyright © 2021 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
import express from 'express'
import fileUpload, { UploadedFile } from 'express-fileupload'
import cors from 'cors'
import { v4 as uuid } from 'uuid'
import { decode } from 'jwt-simple'
import { Space, Ref, Doc, Account, generateId } from '@anticrm/core'
// import { TxFactory } from '@anticrm/core'
import type { Token, IndexedDoc } from '@anticrm/server-core'
import { createElasticAdapter } from '@anticrm/elastic'
import attachment from '@anticrm/attachment'
// import { createContributingClient } from '@anticrm/contrib'
import { Client, ItemBucketMetadata } from 'minio'
// import { createElasticAdapter } from '@anticrm/elastic'
// const BUCKET = 'anticrm-upload-9e4e89c'
// async function awsUpload (file: UploadedFile): Promise<string> {
// const id = uuid()
// const s3 = new S3()
// const resp = await s3.upload({
// Bucket: BUCKET,
// Key: id,
// Body: file.data,
// ContentType: file.mimetype,
// ACL: 'public-read'
// }).promise()
// console.log(resp)
// return id
// }
async function minioUpload (minio: Client, workspace: string, file: UploadedFile): Promise<string> {
const id = uuid()
const meta: ItemBucketMetadata = {
'Content-Type': file.mimetype
}
const resp = await minio.putObject(workspace, id, file.data, file.size, meta)
console.log(resp)
return id
}
// async function createAttachment (endpoint: string, token: string, account: Ref<Account>, space: Ref<Space>, attachedTo: Ref<Doc>, collection: string, name: string, file: string): Promise<void> {
// const txFactory = new TxFactory(account)
// const tx = txFactory.createTxCreateDoc(chunter.class.Attachment, space, {
// attachedTo,
// collection,
// name,
// file
// })
// const url = new URL(`/${token}`, endpoint)
// const client = await createContributingClient(url.href)
// await client.tx(tx)
// client.close()
// }
/**
* @public
* @param port -
*/
export function start (transactorEndpoint: string, elasticUrl: string, minio: Client, port: number): () => void {
const app = express()
app.use(cors())
app.use(fileUpload())
// eslint-disable-next-line @typescript-eslint/no-misused-promises
app.get('/', async (req, res) => {
try {
const token = req.query.token as string
const payload = decode(token, 'secret', false) as Token
const uuid = req.query.file as string
const stat = await minio.statObject(payload.workspace, uuid)
minio.getObject(payload.workspace, uuid, function (err, dataStream) {
if (err !== null) {
return console.log(err)
}
res.status(200)
const contentType = stat.metaData['content-type']
if (contentType !== undefined) {
res.setHeader('Content-Type', contentType)
}
dataStream.on('data', function (chunk) {
res.write(chunk)
})
dataStream.on('end', function () {
res.end()
})
dataStream.on('error', function (err) {
console.log(err)
})
})
} catch (error) {
console.log(error)
res.status(500).send()
}
})
// eslint-disable-next-line @typescript-eslint/no-misused-promises
app.post('/', async (req, res) => {
const file = req.files?.file as UploadedFile
if (file === undefined) {
res.status(400).send()
return
}
const authHeader = req.headers.authorization
if (authHeader === undefined) {
res.status(403).send()
return
}
try {
const token = authHeader.split(' ')[1]
const payload = decode(token ?? '', 'secret', false) as Token
// const fileId = await awsUpload(file as UploadedFile)
const uuid = await minioUpload(minio, payload.workspace, file)
console.log('uploaded uuid', uuid)
const name = req.query.name as string
const space = req.query.space as Ref<Space>
const attachedTo = req.query.attachedTo as Ref<Doc>
// const name = req.query.name as string
// await createAttachment(
// transactorEndpoint,
// token,
// 'core:account:System' as Ref<Account>,
// space,
// attachedTo,
// collection,
// name,
// fileId
// )
const elastic = await createElasticAdapter(elasticUrl, payload.workspace)
const indexedDoc: IndexedDoc = {
id: generateId() + '/attachments/' + name,
_class: attachment.class.Attachment,
space,
modifiedOn: Date.now(),
modifiedBy: 'core:account:System' as Ref<Account>,
attachedTo,
data: file.data.toString('base64')
}
await elastic.index(indexedDoc)
res.status(200).send(uuid)
} catch (error) {
console.log(error)
res.status(500).send()
}
})
const server = app.listen(port)
return () => {
server.close()
}
}

View File

@ -1,17 +0,0 @@
//
// Copyright © 2020, 2021 Anticrm Platform Contributors.
// Copyright © 2021 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
export { start } from './app'

View File

@ -1,9 +0,0 @@
{
"extends": "./node_modules/@anticrm/platform-rig/profiles/default/tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib",
"esModuleInterop": true
}
}