aboutsummaryrefslogtreecommitdiff
path: root/src/app/components/post-attachment/post-attachment.component.ts
blob: 1aeca376c3492919873bac76dab3505a795fda38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Component, Input, OnInit } from '@angular/core';

@Component({
  selector: 'app-post-attachment',
  templateUrl: './post-attachment.component.html',
  styleUrls: ['./post-attachment.component.css']
})
export class PostAttachmentComponent implements OnInit {
  @Input() paramURL: string;
  public isImage = false;
  public showFull = false;
  public fileName: string;
  public fileType: string;

  constructor()
  { }

  ngOnInit(): void {
    this.isImage = this.paramURL.includes('image') && !this.paramURL.endsWith('pdf');
    this.fileType = this.isImage ? 'img' : 'raw';
    if (this.fileType === 'img') {
      this.fileName = this.paramURL.match(/(?!\/)+?[^\/]+?(?=\.)/g)?.pop() ?? 'Attachment';
    }
    else {
      this.fileName = this.paramURL.match(/[^\/]+?$/g)?.pop() ?? 'Attachment';
    }
  }

  toggleShowFull(): void {
    this.showFull = !this.showFull;
  }
}