Skip to content

Commit

Permalink
Update (#1)
Browse files Browse the repository at this point in the history
* Refactor answer-utils file parser

* Refactor shared-types-enums type FileUploadValue

* Upgrade dependencies

* Refactor the data structure for file uploads (close heyform#37)

* Fix submissions not properly displayed after schema change (close heyform#29)

* Release v0.0.6

* Adding environment variables deailing with SSL email endpoints (port 465) (heyform#40)

* Simplify apk process in Dockerfile by using `--no-cache` option (heyform#42)

- Replace the `--update` parameter with `--no-cache` in `apk add`
commands to ensure package indices are updated without leaving a cache.
- Remove the explicit cache removal step since the `--no-cache`
parameter makes it superfluous.

* Add zhTW traditional chinese locale (heyform#41)

---------

Co-authored-by: mufeng <mufeng.me@gmail.com>
Co-authored-by: Ed McLain <ed@edmclain.com>
Co-authored-by: Peter Dave Hello <hsu@peterdavehello.org>
  • Loading branch information
4 people committed Apr 10, 2024
1 parent aa49539 commit 145341a
Show file tree
Hide file tree
Showing 45 changed files with 1,295 additions and 609 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG APP_PATH=/app
WORKDIR $APP_PATH

RUN npm install -g pnpm
RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*
RUN apk add --no-cache python3 make g++

COPY package.json $APP_PATH/package.json
COPY pnpm-lock.yaml $APP_PATH/pnpm-lock.yaml
Expand All @@ -22,7 +22,7 @@ ARG APP_PATH=/app
WORKDIR $APP_PATH

RUN npm install -g pnpm
RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*
RUN apk add --no-cache python3 make g++

COPY --from=base $APP_PATH/packages/server/dist ./dist
COPY --from=base $APP_PATH/packages/server/mongoose ./mongoose
Expand Down
4 changes: 2 additions & 2 deletions packages/answer-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@heyform-inc/answer-utils",
"description": "HeyForm Answer Utils",
"version": "1.0.1",
"version": "1.0.3",
"homepage": "https://heyform.net",
"author": "Heyooo, Inc.",
"license": "AGPL-3.0",
Expand All @@ -21,7 +21,7 @@
"prebuild": "npm run clean"
},
"peerDependencies": {
"@heyform-inc/shared-types-enums": "^1.0.0",
"@heyform-inc/shared-types-enums": "^1.0.1",
"@heyform-inc/utils": "^1.0.1",
"big.js": "^6.2.1",
"dayjs": "^1.11.3",
Expand Down
13 changes: 8 additions & 5 deletions packages/answer-utils/src/answer-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ function fileUpload(answer: Answer, livePreview = false) {
}
}

const filename = helper.isValid(answer.value.filename) ? answer.value.filename : ''
const urls = [answer.value.cdnUrlPrefix, answer.value.cdnKey].filter(helper.isValid)
const url = urls.length > 0 ? urls.join('/') : ''
if (helper.isURL(answer.value)) {
return {
filename: '',
url: answer.value
}
}

return {
filename,
url
filename: answer.value.filename || '',
url: answer.value.url
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,17 @@ Array [
"properties": Object {},
"title": "🈴️ Upload you avatar ",
"value": Object {
"cdnKey": "qCpteNRi2SiO_avatar.jpg",
"cdnUrlPrefix": "https://heyformhq.com",
"filename": "avatar.jpg",
"url": "https://heyformhq.com/qCpteNRi2SiO_avatar.jpg",
},
},
Object {
"id": "NqCpSqCpteiO",
"kind": "file_upload",
"properties": Object {},
"title": "You sig here",
"value": "https://heyform.net/sig.jpg",
},
Object {
"id": "qFN5cteg6SOa",
"kind": "rating",
Expand Down Expand Up @@ -303,11 +309,17 @@ Array [
"properties": Object {},
"title": "🈴️ Upload you avatar ",
"value": Object {
"cdnKey": "qCpteNRi2SiO_avatar.jpg",
"cdnUrlPrefix": "https://heyformhq.com",
"filename": "avatar.jpg",
"url": "https://heyformhq.com/qCpteNRi2SiO_avatar.jpg",
},
},
Object {
"id": "NqCpSqCpteiO",
"kind": "file_upload",
"properties": Object {},
"title": "You sig here",
"value": "https://heyform.net/sig.jpg",
},
Object {
"id": "qFN5cteg6SOa",
"kind": "rating",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ In the Land of Mordor where the shadows lie.",
"required": false,
},
},
Object {
"id": "NqCpSqCpteiO",
"kind": "file_upload",
"title": "You sig here",
"validations": Object {
"required": false,
},
},
Object {
"id": "qFN5cteg6SOa",
"kind": "rating",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`should convert value to api object 1`] = `
Object {
"(ID: EF9tbsJj3CNZ) 🐶 Choose the dog ": "Choice 3",
"(ID: MVlZfnmjZlye) 👋 Just choose one": "🍍 Pineapple",
"(ID: NqCpSqCpteiO) You sig here": " (https://heyform.net/sig.jpg)",
"(ID: NteSqF9g5cOa6) Input table": "Ivan, 16
Jack Smith, 24",
"(ID: X9F47wrnJImk) 👍 Do you agree with us ": "No",
Expand All @@ -20,6 +21,7 @@ exports[`should convert value to flat json 1`] = `
Object {
"EF9tbsJj3CNZ": "Choice 3",
"MVlZfnmjZlye": "🍍 Pineapple",
"NqCpSqCpteiO": " (https://heyform.net/sig.jpg)",
"NteSqF9g5cOa6": "Ivan, 16
Jack Smith, 24",
"X9F47wrnJImk": "No",
Expand Down Expand Up @@ -69,6 +71,11 @@ exports[`should convert value to html 1`] = `
<p>avatar.jpg (https://heyformhq.com/qCpteNRi2SiO_avatar.jpg)</p>
</li>
<li>
<h3>You sig here</h3>
<p> (https://heyform.net/sig.jpg)</p>
</li>
<li>
<h3>🪐 Rate here </h3>
<p>5</p>
Expand All @@ -91,6 +98,10 @@ exports[`should convert value to json 1`] = `
Object {
"EF9tbsJj3CNZ": "Choice 3",
"MVlZfnmjZlye": "🍍 Pineapple",
"NqCpSqCpteiO": Object {
"filename": "",
"url": "https://heyform.net/sig.jpg",
},
"NteSqF9g5cOa6": Array [
Object {
"age": "16",
Expand Down Expand Up @@ -139,6 +150,9 @@ Choice 3
🈴️ Upload you avatar
avatar.jpg (https://heyformhq.com/qCpteNRi2SiO_avatar.jpg)
You sig here
(https://heyform.net/sig.jpg)
🪐 Rate here
5
Expand Down
8 changes: 8 additions & 0 deletions packages/answer-utils/test/fixtures/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@
"title": "🈴️ Upload you avatar ",
"kind": "file_upload"
},
{
"validations": {
"required": false
},
"id": "NqCpSqCpteiO",
"title": "You sig here",
"kind": "file_upload"
},
{
"validations": {
"required": false
Expand Down
4 changes: 2 additions & 2 deletions packages/answer-utils/test/fixtures/values.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"value": ["1Fl7MP9Nv2TM"]
},
"Ri2SiOqCpteN": "let x: int = 0\n\n\n func (x: int) {\nreturn x * 3\n}\n",
"NqCpSqCpteiO": "https://heyform.net/sig.jpg",
"qCpteNRi2SiO": {
"cdnKey": "qCpteNRi2SiO_avatar.jpg",
"filename": "avatar.jpg",
"cdnUrlPrefix": "https://heyformhq.com"
"url": "https://heyformhq.com/qCpteNRi2SiO_avatar.jpg"
},
"qFN5cteg6SOa": 5,
"NteSqF9g5cOa6": [
Expand Down
6 changes: 3 additions & 3 deletions packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "server",
"version": "0.0.5",
"version": "0.0.6",
"homepage": "https://heyform.net",
"author": "Heyooo, Inc.",
"license": "AGPL-3.0",
Expand All @@ -18,8 +18,8 @@
"prebuild": "rimraf dist"
},
"dependencies": {
"@heyform-inc/answer-utils": "1.0.1",
"@heyform-inc/shared-types-enums": "1.0.0",
"@heyform-inc/answer-utils": "1.0.3",
"@heyform-inc/shared-types-enums": "1.0.1",
"@heyform-inc/utils": "1.0.1",
"@nestjs/bull": "0.3.1",
"@nestjs/common": "7.4.4",
Expand Down
19 changes: 1 addition & 18 deletions packages/server/src/common/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Transform } from 'class-transformer'
import { IsInt, IsNumber, IsOptional, IsString, IsUrl } from 'class-validator'
import { IsInt, IsOptional, IsString, IsUrl } from 'class-validator'
import { APP_HOMEPAGE_URL } from '@environments'

export class ImageResizingDto {
Expand Down Expand Up @@ -28,23 +28,6 @@ export class ImageResizingDto {
h?: number
}

export class CdnCallbackDto {
@IsString()
key: string

@IsString()
hash: string

@IsNumber()
size: number

@IsString()
name: string

@IsString()
endUser: string
}

export class ExportSubmissionsDto {
@IsString()
formId: string
Expand Down
13 changes: 1 addition & 12 deletions packages/server/src/common/graphql/endpoint.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import { Field, InputType, ObjectType } from '@nestjs/graphql'
import { IsOptional, IsString } from 'class-validator'
import { GraphQLJSONObject } from 'graphql-type-json'

import { CdnTokenInput } from './user.graphql'

@InputType()
export class UploadFormFileInput extends CdnTokenInput {
@Field()
formId: string
}

@InputType()
export class UploadFormSignatureInput {
@Field()
Expand Down Expand Up @@ -106,10 +98,7 @@ export class UploadFormFileType {
filename: string

@Field()
cdnKey: string

@Field()
cdnUrlPrefix: string
url: string

@Field()
size: number
Expand Down
12 changes: 0 additions & 12 deletions packages/server/src/common/graphql/team.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@ export class InviteMemberInput extends TeamDetailInput {
emails: string[]
}

@InputType()
export class TeamCdnTokenInput {
@Field()
teamId: string

@Field()
mime: string

@Field()
filename: string
}

@InputType()
export class UpdateTeamInput extends TeamDetailInput {
@Field({ nullable: true })
Expand Down
21 changes: 0 additions & 21 deletions packages/server/src/common/graphql/user.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ import { IsEmail, IsOptional, Length, Matches } from 'class-validator'

import { LowerCase } from '@utils'

@InputType()
export class CdnTokenInput {
@Field()
mime: string

@Field()
filename: string
}

@InputType()
export class UpdateUserInput {
@Field({ nullable: true })
Expand Down Expand Up @@ -63,18 +54,6 @@ export class UpdateUserPasswordInput {
newPassword: string
}

@ObjectType()
export class CdnTokenType {
@Field()
token: string

@Field()
urlPrefix: string

@Field()
key: string
}

@ObjectType()
export class UserDetailType {
@Field()
Expand Down
4 changes: 3 additions & 1 deletion packages/server/src/config/smtp/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { SMTP_HOST, SMTP_PASSWORD, SMTP_PORT, SMTP_USER } from '@environments'
import { SMTP_HOST, SMTP_PASSWORD, SMTP_PORT, SMTP_USER, SMTP_SECURE, SMTP_IGNORE_CERT } from '@environments'
import { SmtpOptions } from '@utils'

export const SmtpOptionsFactory = (): SmtpOptions => ({
host: SMTP_HOST,
port: SMTP_PORT,
user: SMTP_USER,
password: SMTP_PASSWORD,
secure: SMTP_SECURE,
ignoreCert: SMTP_IGNORE_CERT,
pool: true,
logger: false
})
6 changes: 5 additions & 1 deletion packages/server/src/controller/upload.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ export class UploadController {
})
})
)
async index(@UploadedFile() file: Express.Multer.File): Promise<{ url: string }> {
async index(
@UploadedFile() file: Express.Multer.File
): Promise<{ filename: string; url: string; size: number }> {
return {
filename: file.originalname,
size: file.size,
url: APP_HOMEPAGE_URL.replace(/\/+$/, '') + `/static/upload/${file.filename}`
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/environments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export const SMTP_HOST: string = process.env.SMTP_HOST
export const SMTP_PORT: number = +process.env.SMTP_PORT
export const SMTP_USER: string = process.env.SMTP_USER
export const SMTP_PASSWORD: string = process.env.SMTP_PASSWORD
export const SMTP_SECURE: boolean = helper.isTrue(process.env.SMTP_SECURE)
export const SMTP_IGNORE_CERT: boolean = helper.isTrue(process.env.SMTP_IGNORE_CERT)

// Google recaptcha
export const GOOGLE_RECAPTCHA_KEY: string = process.env.GOOGLE_RECAPTCHA_KEY
Expand Down
11 changes: 9 additions & 2 deletions packages/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as rateLimit from 'express-rate-limit'
import * as helmet from 'helmet'
import * as serveStatic from 'serve-static'

import { ms } from '@heyform-inc/utils'
import { helper, ms } from '@heyform-inc/utils'

import { APP_LISTEN_HOSTNAME, APP_LISTEN_PORT, STATIC_DIR, VIEW_DIR } from '@environments'
import { Logger, hbs } from '@utils'
Expand Down Expand Up @@ -36,7 +36,14 @@ async function bootstrap() {
'/static',
serveStatic(STATIC_DIR, {
maxAge: '30d',
extensions: ['png', 'svg', 'js', 'css']
extensions: ['jpg', 'jpeg', 'bmp', 'webp', 'gif', 'png', 'svg', 'js', 'css'],
setHeaders: (res, path) => {
const { attname } = res.req.query

if (helper.isValid(attname)) {
res.setHeader('Content-Disposition', `attachment; filename="${attname}"`)
}
}
})
)

Expand Down

0 comments on commit 145341a

Please sign in to comment.