Skip to content

Commit

Permalink
feat(admin): file upload input and yield
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobuddy committed Sep 25, 2024
1 parent a0ab6b6 commit 98bf8ee
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"yaml.schemas": {
"./packages/core/manifest/src/manifest/json-schema/schema.json": "**/manifest/**/**backend.yml"
"./packages/core/json-schema/src/schema/schema.json": "**/manifest/**/**backend.yml"
},

"workbench.colorCustomizations": {
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

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

Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { NgIf } from '@angular/common'
import { NgClass, NgIf } from '@angular/common'
import { Component, Input } from '@angular/core'
import { TruncatePipe } from '../../pipes/truncate.pipe'
import { environment } from '../../../../../environments/environment'

@Component({
selector: 'app-link-yield',
standalone: true,
imports: [NgIf, TruncatePipe],
imports: [NgIf, NgClass, TruncatePipe],
template: ` <a
[href]="value"
[href]="external ? value : storageBaseUrl + '/' + value"
[download]="!external"
target="_blank"
class="is-inline-flex is-align-items-center"
*ngIf="value"
>
<i class="icon icon-external-link mr-1"></i>
<span *ngIf="compact">{{ value | truncate : 44 }}</span>
<i
class="icon icon-external-link mr-1"
[ngClass]="{
'icon-external-link': external,
'icon-download': !external
}"
></i>
<span *ngIf="compact">{{ value | truncate: 44 }}</span>
<span *ngIf="!compact">{{ value }}</span>
</a>
<span class="is-nowrap" *ngIf="!value"> - </span>`,
Expand All @@ -22,4 +30,7 @@ import { TruncatePipe } from '../../pipes/truncate.pipe'
export class LinkYieldComponent {
@Input() value: string
@Input() compact: boolean = true
@Input() external: boolean = true

storageBaseUrl = environment.storageBaseUrl
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ import { TimestampYieldComponent } from './timestamp-yield/timestamp-yield.compo
[value]="value"
></app-number-yield>
<app-link-yield
*ngIf="prop.type === PropType.Link"
*ngIf="prop.type === PropType.Link || prop.type === PropType.File"
[value]="value"
[external]="prop.type === PropType.Link"
[compact]="compact"
></app-link-yield>
<app-boolean-yield
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const environment = {
production: false,
apiBaseUrl: 'http://localhost:1111/api',
storageBaseUrl: '/storage'
storageBaseUrl: 'http://localhost:1111/storage'
}
5 changes: 4 additions & 1 deletion packages/core/manifest/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ lerna-debug.log*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/extensions.json

# Storage
/public
1 change: 1 addition & 0 deletions packages/core/manifest/manifest/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ entities:
- { name: birthdate, type: date }
- { name: aquiredAt, type: timestamp }
- { name: hiddenProp, type: boolean, hidden: true }
- { name: certificate, type: file }
belongsTo:
- { name: owner, entity: User }
policies:
Expand Down
3 changes: 2 additions & 1 deletion packages/core/manifest/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ async function bootstrap() {
}

const adminPanelFolder: string = configService.get('paths').adminPanelFolder

app.use(express.static(adminPanelFolder))

app.use('/storage', express.static('public/storage'))

// Redirect all requests to the client app index.
app.use((req, res, next) => {
if (req.url.startsWith('/api') || req.url.startsWith('/storage')) {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/manifest/src/upload/services/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { STORAGE_PATH } from '../../constants'

import * as fs from 'fs'
import * as mkdirp from 'mkdirp'
import * as uniqid from 'uniqid'
import uniqid from 'uniqid'

@Injectable()
export class StorageService {
Expand Down Expand Up @@ -41,7 +41,7 @@ export class StorageService {

const filePath: string = `${folder}/${uniqid()}-${file.originalname}`

fs.writeFileSync(filePath, file.buffer)
fs.writeFileSync(`${STORAGE_PATH}/${filePath}`, file.buffer)

return filePath
}
Expand All @@ -61,9 +61,9 @@ export class StorageService {
new Date().toLocaleString('en-us', { month: 'short' }) +
new Date().getFullYear()

const folder: string = `${STORAGE_PATH}/${kebabize(entity)}/${kebabize(property)}/${dateString}`
const folder: string = `${kebabize(entity)}/${kebabize(property)}/${dateString}`

mkdirp.sync(folder)
mkdirp.sync(`${STORAGE_PATH}/${folder}`)

return folder
}
Expand Down

0 comments on commit 98bf8ee

Please sign in to comment.