1
- import type { NextPage } from 'next'
2
- import Head from 'next/head'
3
- import Image from 'next/image'
4
- import styles from '../styles/Home.module.css'
1
+ import {
2
+ Container ,
3
+ Title ,
4
+ DropzoneSection ,
5
+ DropzoneInputContainer ,
6
+ DropzoneFileInput ,
7
+ DropzoneText ,
8
+ Footer ,
9
+ FooterText ,
10
+ FooterLink ,
11
+ FooterImageAvatar ,
12
+ LoaderContainer ,
13
+ LoadingText ,
14
+ Table
15
+ } from "../styles/homePage" ;
16
+ import { Download , Tool } from "react-feather" ;
17
+ import Dropzone from 'react-dropzone' ;
18
+ import { useEffect , useState } from "react" ;
19
+ import sendFiles from "../utils/sendFiles" ;
20
+ import { RingLoader } from "react-spinners" ;
21
+ import MimeTypes from 'mime-types' ;
22
+ import { useRouter } from "next/dist/client/router" ;
5
23
6
- const Home : NextPage = ( ) => {
7
- return (
8
- < div className = { styles . container } >
9
- < Head >
10
- < title > Create Next App</ title >
11
- < meta name = "description" content = "Generated by create next app" />
12
- < link rel = "icon" href = "/favicon.ico" />
13
- </ Head >
24
+ export default function Home ( ) {
25
+ const [ files , setFiles ] = useState < any > ( [ ] ) ;
26
+ const [ results , setResults ] = useState < any > ( [ ] ) ;
14
27
15
- < main className = { styles . main } >
16
- < h1 className = { styles . title } >
17
- Welcome to < a href = "https://nextjs.org" > Next.js!</ a >
18
- </ h1 >
28
+ const [ loading , setLoading ] = useState < boolean > ( false ) ;
19
29
20
- < p className = { styles . description } >
21
- Get started by editing{ ' ' }
22
- < code className = { styles . code } > pages/index.tsx</ code >
23
- </ p >
30
+ useEffect ( ( ) => {
31
+ async function getResultFiles ( ) {
32
+ const response = await sendFiles ( files ) ;
33
+ setResults ( response ) ;
34
+ setFiles ( [ ] ) ;
35
+ setLoading ( false ) ;
36
+ }
24
37
25
- < div className = { styles . grid } >
26
- < a href = "https://nextjs.org/docs" className = { styles . card } >
27
- < h2 > Documentation → </ h2 >
28
- < p > Find in-depth information about Next.js features and API. </ p >
29
- </ a >
38
+ if ( files . length >= 1 ) {
39
+ setLoading ( true ) ;
40
+ getResultFiles ( ) ;
41
+ }
42
+ } , [ files ] ) ;
30
43
31
- < a href = "https://nextjs.org/learn" className = { styles . card } >
32
- < h2 > Learn →</ h2 >
33
- < p > Learn about Next.js in an interactive course with quizzes!</ p >
34
- </ a >
44
+ async function getFile ( index :number ) {
45
+ const fileDataUrl = 'data:' + MimeTypes . lookup ( results [ index ] . filename ) + ';base64,' + results [ index ] . file ;
35
46
36
- < a
37
- href = "https://github.com/vercel/next.js/tree/master/examples"
38
- className = { styles . card }
39
- >
40
- < h2 > Examples →</ h2 >
41
- < p > Discover and deploy boilerplate example Next.js projects.</ p >
42
- </ a >
47
+ let downloadElement = document . getElementById ( 'downloadFile' ) ;
43
48
44
- < a
45
- href = "https://vercel.com/new?utm_source=create-next-app& utm_medium = default - template & utm_campaign = create - next - app "
46
- className = { styles . card }
47
- >
48
- < h2 > Deploy →</ h2 >
49
- < p >
50
- Instantly deploy your Next.js site to a public URL with Vercel.
51
- </ p >
52
- </ a >
53
- </ div >
54
- </ main >
49
+ if ( ! downloadElement ) {
50
+ const aElement = document . createElement ( 'a' )
51
+ aElement . setAttribute ( 'href' , fileDataUrl ) ;
52
+ aElement . setAttribute ( 'download' , results [ index ] . filename ) ;
53
+ aElement . setAttribute ( 'id' , 'downloadFile' ) ;
54
+ document . body . appendChild ( aElement ) ;
55
+ downloadElement = document . getElementById ( 'downloadFile' ) ;
56
+ }
57
+ else {
58
+ downloadElement . setAttribute ( 'href' , fileDataUrl ) ;
59
+ downloadElement . setAttribute ( 'download' , results [ index ] . filename ) ;
60
+ }
61
+
62
+ downloadElement ?. click ( ) ;
63
+ }
55
64
56
- < footer className = { styles . footer } >
57
- < a
58
- href = "https://vercel.com?utm_source=create-next-app& utm_medium = default - template & utm_campaign = create - next - app "
59
- target = "_blank"
60
- rel = "noopener noreferrer"
61
- >
62
- Powered by{ ' ' }
63
- < span className = { styles . logo } >
64
- < Image src = "/vercel.svg" alt = "Vercel Logo" width = { 72 } height = { 16 } />
65
- </ span >
66
- </ a >
67
- </ footer >
68
- </ div >
69
- )
70
- }
65
+ function backToStart ( ) {
66
+ setResults ( [ ] ) ;
67
+ setFiles ( [ ] ) ;
68
+ setLoading ( false ) ;
69
+ }
71
70
72
- export default Home
71
+ return (
72
+ < Container >
73
+
74
+ < Title onClick = { backToStart } >
75
+ < Tool /> Metadata Cleaner< Tool />
76
+ </ Title >
77
+
78
+ {
79
+ loading ? (
80
+ < LoaderContainer >
81
+ < RingLoader size = { 150 } loading = { loading } color = "#6B4F4F" />
82
+ < LoadingText > Loading...</ LoadingText >
83
+ </ LoaderContainer >
84
+ )
85
+ : null
86
+ }
87
+ {
88
+ results . length <= 0 && ! loading ? (
89
+ < Dropzone multiple = { true } onDrop = { ( acceptedFiles :any ) => setFiles ( acceptedFiles ) } >
90
+ { ( { getRootProps, getInputProps} ) => (
91
+ < DropzoneSection >
92
+ < DropzoneInputContainer { ...getRootProps ( ) } >
93
+ < DropzoneFileInput { ...getInputProps ( ) } />
94
+ < DropzoneText > Drop or click to insert your files!</ DropzoneText >
95
+ </ DropzoneInputContainer >
96
+ </ DropzoneSection >
97
+ ) }
98
+ </ Dropzone >
99
+ ) : null
100
+ }
101
+
102
+ {
103
+ results . length > 0 && ! loading ? (
104
+ < Table >
105
+ < tr >
106
+ < th > Filename</ th >
107
+ < th > Status</ th >
108
+ < th > Download</ th >
109
+ </ tr >
110
+ { results . map ( ( result :any , index :number ) => (
111
+ < tr key = { index } >
112
+ < td > { result . filename } </ td >
113
+ < td > { result . status } </ td >
114
+ < td > < Download onClick = { ( ) => getFile ( index ) } /> </ td >
115
+
116
+ </ tr >
117
+ ) ) }
118
+ </ Table >
119
+ ) : null
120
+ }
121
+
122
+
123
+ < Footer >
124
+ < FooterText >
125
+ Made by{ ' ' }
126
+ < FooterLink href = { process . env . NEXT_PUBLIC_GITHUB } >
127
+ DPBM
128
+ < FooterImageAvatar src = { process . env . NEXT_PUBLIC_GITHUB_AVATAR } alt = "Dpbm Avatar" />
129
+ </ FooterLink >
130
+ </ FooterText >
131
+ </ Footer >
132
+
133
+ </ Container >
134
+ ) ;
135
+ }
0 commit comments