Skip to content

Commit

Permalink
Merge pull request #2 from Saebasol/develop
Browse files Browse the repository at this point in the history
feat(src): add src
  • Loading branch information
SaidBySolo authored Apr 21, 2021
2 parents e7f62a4 + 530deb9 commit 0864a03
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 6 deletions.
92 changes: 86 additions & 6 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"file-saver": "^2.0.5",
"jszip": "^3.5.0",
"normalize.css": "^8.0.1",
"react": "^17.0.0",
"react-dom": "^17.0.0"
},
Expand Down
59 changes: 59 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as React from 'react'
import JSZip from 'jszip'
import saveAs from 'file-saver'
import api from './api'


function App() {
const { useState, useEffect } = React

const [index, setIndex] = useState(0)

async function mainFunc() {
const params = new URLSearchParams(window.location.search)
const downloadIndex = params.get("index")

if (!downloadIndex || !Number.isNaN(downloadIndex)) {
alert("인자값이 주어지지 않았습니다!")
return
}
if (window.confirm("브라우저의 한계로 많은 이미지는 다운로드 할수 없을수도 있습니다. 시도하시겠습니까?")) {
const zip = new JSZip()
const imageFolder = zip.folder(downloadIndex)

const imageInfoResponse = await fetch(api + `hitomi/images/${downloadIndex}`)
if (imageInfoResponse.status == 404) {
alert("찾을수 없습니다.")
return
}
const imagesInfo = await imageInfoResponse.json()

let count = 0

const downloadImage = imagesInfo.files.map(async (imageInfo, index) => {
const image = await fetch(api + "proxy/" + imageInfo.image)
const imgBlob = await image.blob()

imageFolder.file(imageInfo.name, imgBlob)
setIndex(count += 1)
})

await Promise.all(downloadImage)
const content = await zip.generateAsync({ type: 'blob' })
saveAs.saveAs(content, `${downloadIndex}.zip`)
}
}

useEffect(() => {
mainFunc()
}, [])

return (
<div className='App'>
<h1>다운로드 중: {index}</h1>
</div>

)
}

export default App;
1 change: 1 addition & 0 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "https://beta.doujinshiman.ga/v4/api/"
17 changes: 17 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import App from './App.jsx'
import 'normalize.css'

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root'),
);

// Hot Module Replacement (HMR) - Remove this snippet to remove HMR.
// Learn more: https://www.snowpack.dev/concepts/hot-module-replacement
if (import.meta.hot) {
import.meta.hot.accept();
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,11 @@ normalize-url@^4.1.0:
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.5.0.tgz#453354087e6ca96957bd8f5baf753f5982142129"
integrity sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==

normalize.css@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/normalize.css/-/normalize.css-8.0.1.tgz#9b98a208738b9cc2634caacbc42d131c97487bf3"
integrity sha512-qizSNPO93t1YUuUhP22btGOo3chcvDFqFaj2TRybP0DMxkHOCTYwp3n34fel4a31ORXy4m1Xq0Gyqpb5m33qIg==

npm-run-path@^4.0.0, npm-run-path@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea"
Expand Down

0 comments on commit 0864a03

Please sign in to comment.