Showing
5 changed files
with
75 additions
and
4 deletions
... | @@ -9,6 +9,7 @@ | ... | @@ -9,6 +9,7 @@ |
9 | "@testing-library/user-event": "^12.1.10", | 9 | "@testing-library/user-event": "^12.1.10", |
10 | "@toast-ui/react-image-editor": "3.14.2", | 10 | "@toast-ui/react-image-editor": "3.14.2", |
11 | "@types/fabric": "^4.2.5", | 11 | "@types/fabric": "^4.2.5", |
12 | + "axios": "^0.21.1", | ||
12 | "fabric": "^4.4.0", | 13 | "fabric": "^4.4.0", |
13 | "next": "^10.0.5", | 14 | "next": "^10.0.5", |
14 | "react": "^17.0.2", | 15 | "react": "^17.0.2", | ... | ... |
src/api.ts
0 → 100644
1 | +import axios from "axios"; | ||
2 | + | ||
3 | +const baseURL = "https://9davbjzey4.execute-api.ap-northeast-2.amazonaws.com"; | ||
4 | + | ||
5 | +export const postGif = async (formData) => { | ||
6 | + console.log("file", formData); | ||
7 | + const { data } = await axios.post(baseURL, formData); | ||
8 | + | ||
9 | + return data; | ||
10 | +}; | ||
11 | + | ||
12 | +export const getGif = async (id) => { | ||
13 | + const { data } = await axios.get(baseURL, { | ||
14 | + params: { | ||
15 | + id: id, | ||
16 | + }, | ||
17 | + }); | ||
18 | + | ||
19 | + return data; | ||
20 | +}; |
... | @@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from "react"; | ... | @@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from "react"; |
2 | import styled from "styled-components"; | 2 | import styled from "styled-components"; |
3 | import TuiImageEditor from "tui-image-editor"; | 3 | import TuiImageEditor from "tui-image-editor"; |
4 | import "gif-generator/dist/gif-generator"; | 4 | import "gif-generator/dist/gif-generator"; |
5 | +import { getGif, postGif } from "api"; | ||
5 | 6 | ||
6 | const GifEditor = ({ previewURL }) => { | 7 | const GifEditor = ({ previewURL }) => { |
7 | // const [canvas, setCanvas] = useState<HTMLCanvasElement>(); | 8 | // const [canvas, setCanvas] = useState<HTMLCanvasElement>(); |
... | @@ -10,6 +11,9 @@ const GifEditor = ({ previewURL }) => { | ... | @@ -10,6 +11,9 @@ const GifEditor = ({ previewURL }) => { |
10 | 11 | ||
11 | const rootEl = useRef(); | 12 | const rootEl = useRef(); |
12 | 13 | ||
14 | + const [download, setDownload] = useState(null); | ||
15 | + const [blob, setBlob] = useState(null); | ||
16 | + | ||
13 | useEffect(() => { | 17 | useEffect(() => { |
14 | // if (window) { | 18 | // if (window) { |
15 | // setCanvas( | 19 | // setCanvas( |
... | @@ -59,15 +63,17 @@ const GifEditor = ({ previewURL }) => { | ... | @@ -59,15 +63,17 @@ const GifEditor = ({ previewURL }) => { |
59 | const gifGenerator = new GifGenerator(imageEditor._graphics.getCanvas()); | 63 | const gifGenerator = new GifGenerator(imageEditor._graphics.getCanvas()); |
60 | gifGenerator.make().then( | 64 | gifGenerator.make().then( |
61 | (blob) => { | 65 | (blob) => { |
62 | - console.log("blob", blob); | 66 | + setBlob(blob); |
63 | - console.log(window.URL.createObjectURL(blob)); | 67 | + console.log("blobaaa", blob); |
64 | - window.open(window.URL.createObjectURL(blob)); | 68 | + // console.log(window.URL.createObjectURL(blob)); |
69 | + setDownload(window.URL.createObjectURL(blob)); | ||
65 | }, | 70 | }, |
66 | (error) => { | 71 | (error) => { |
67 | alert(error); | 72 | alert(error); |
68 | } | 73 | } |
69 | ); | 74 | ); |
70 | }; | 75 | }; |
76 | + //localhost:3000/f431b497-4ece-46d4-8708-8b1703d21b6e | ||
71 | 77 | ||
72 | // useEffect(() => { | 78 | // useEffect(() => { |
73 | // // if (canvas) setGifGenerator(new GifGenerator(canvas._graphics.getCanvas())); | 79 | // // if (canvas) setGifGenerator(new GifGenerator(canvas._graphics.getCanvas())); |
... | @@ -106,10 +112,25 @@ const GifEditor = ({ previewURL }) => { | ... | @@ -106,10 +112,25 @@ const GifEditor = ({ previewURL }) => { |
106 | // // console.log(canvas.getContext("2d")); | 112 | // // console.log(canvas.getContext("2d")); |
107 | // } | 113 | // } |
108 | // }, [canvas]); | 114 | // }, [canvas]); |
115 | + const handleUpload = async () => { | ||
116 | + const file = new File([blob], "file.gif"); | ||
117 | + const formData = new FormData(); | ||
118 | + formData.append("gif", file); | ||
119 | + const res = await postGif(formData); | ||
120 | + console.log(res); | ||
121 | + }; | ||
109 | 122 | ||
110 | return ( | 123 | return ( |
111 | <> | 124 | <> |
112 | <Wrapper> | 125 | <Wrapper> |
126 | + {download && ( | ||
127 | + <div style={{ display: "flex" }}> | ||
128 | + <a href={download} download="new_file_name.gif"> | ||
129 | + download | ||
130 | + </a> | ||
131 | + <div onClick={handleUpload}>server upload</div> | ||
132 | + </div> | ||
133 | + )} | ||
113 | <div onClick={render} className="upload"> | 134 | <div onClick={render} className="upload"> |
114 | Save | 135 | Save |
115 | </div> | 136 | </div> |
... | @@ -150,7 +171,7 @@ const GifEditor = ({ previewURL }) => { | ... | @@ -150,7 +171,7 @@ const GifEditor = ({ previewURL }) => { |
150 | const Wrapper = styled.div` | 171 | const Wrapper = styled.div` |
151 | position: fixed; | 172 | position: fixed; |
152 | width: 90%; | 173 | width: 90%; |
153 | - top: 10rem; | 174 | + top: 15rem; |
154 | border-radius: 1.5rem; | 175 | border-radius: 1.5rem; |
155 | box-shadow: ${({ theme }) => theme.boxShadow.normal}; | 176 | box-shadow: ${({ theme }) => theme.boxShadow.normal}; |
156 | display: flex; | 177 | display: flex; | ... | ... |
src/pages/[id].tsx
0 → 100644
1 | +import { getGif } from "api"; | ||
2 | +import { useRouter } from "next/dist/client/router"; | ||
3 | +import { useEffect, useState } from "react"; | ||
4 | + | ||
5 | +const Detail = () => { | ||
6 | + const id = useRouter().query.id; | ||
7 | + | ||
8 | + return ( | ||
9 | + <div> | ||
10 | + <img | ||
11 | + src={`https://9davbjzey4.execute-api.ap-northeast-2.amazonaws.com/?id=${id}`} | ||
12 | + /> | ||
13 | + </div> | ||
14 | + ); | ||
15 | +}; | ||
16 | + | ||
17 | +export default Detail; |
... | @@ -1856,6 +1856,13 @@ axe-core@^4.0.2: | ... | @@ -1856,6 +1856,13 @@ axe-core@^4.0.2: |
1856 | resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.1.2.tgz#7cf783331320098bfbef620df3b3c770147bc224" | 1856 | resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.1.2.tgz#7cf783331320098bfbef620df3b3c770147bc224" |
1857 | integrity sha512-V+Nq70NxKhYt89ArVcaNL9FDryB3vQOd+BFXZIfO3RP6rwtj+2yqqqdHEkacutglPaZLkJeuXKCjCJDMGPtPqg== | 1857 | integrity sha512-V+Nq70NxKhYt89ArVcaNL9FDryB3vQOd+BFXZIfO3RP6rwtj+2yqqqdHEkacutglPaZLkJeuXKCjCJDMGPtPqg== |
1858 | 1858 | ||
1859 | +axios@^0.21.1: | ||
1860 | + version "0.21.1" | ||
1861 | + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" | ||
1862 | + integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== | ||
1863 | + dependencies: | ||
1864 | + follow-redirects "^1.10.0" | ||
1865 | + | ||
1859 | axobject-query@^2.2.0: | 1866 | axobject-query@^2.2.0: |
1860 | version "2.2.0" | 1867 | version "2.2.0" |
1861 | resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be" | 1868 | resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be" |
... | @@ -3184,6 +3191,11 @@ flatted@^3.1.0: | ... | @@ -3184,6 +3191,11 @@ flatted@^3.1.0: |
3184 | resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469" | 3191 | resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469" |
3185 | integrity sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA== | 3192 | integrity sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA== |
3186 | 3193 | ||
3194 | +follow-redirects@^1.10.0: | ||
3195 | + version "1.14.1" | ||
3196 | + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.1.tgz#d9114ded0a1cfdd334e164e6662ad02bfd91ff43" | ||
3197 | + integrity sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg== | ||
3198 | + | ||
3187 | foreach@^2.0.5: | 3199 | foreach@^2.0.5: |
3188 | version "2.0.5" | 3200 | version "2.0.5" |
3189 | resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99" | 3201 | resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99" | ... | ... |
-
Please register or login to post a comment