Skip to content

Commit

Permalink
finally literally made a copy-paste
Browse files Browse the repository at this point in the history
  • Loading branch information
va9iff committed May 9, 2022
1 parent 7b0e2ab commit a829198
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// const WONU = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname + window.location.search
const WONU = window.location.href

window.repo = "WON"
window.user = "va9iff"
const repo = "WON"
const user = "va9iff"
const url = `https://api.github.com/repos/${user}/${repo}/contents/`


Expand Down
76 changes: 75 additions & 1 deletion src/apps/files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,81 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Nunito&display=swap" rel="stylesheet">

<script src="https://raw.githubusercontent.com/va9iff/WON/master/src/api.js"></script>
<script>
// const WONU = "http://127.0.0.1:5000/" //export
// const WONU = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname + window.location.search
const WONU = window.location.href

repo = "WON"
user = "va9iff"
const url = `https://api.github.com/repos/${user}/${repo}/contents/`



async function browse(path="tmp") {
try {
const response = await fetch(`http://localhost:5000/browse/${path}`);
try{
const jsoned = await response.json();
return jsoned
}
catch(err){
return response
}
console.log(jsoned)

// console.log(response)
} catch (error) {
console.error(error);
}
}

async function save(file, name, folder="") {
const formData = new FormData()
formData.append("file", file)
formData.append("name", name)
formData.append("folder", folder)
try {
const res = await axios.post("http://localhost:5000/save", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
})
return res
} catch (err) {
console.log(err)
}
}

async function browseOnGitHub(path = "") {
path = path.replace('>',"/")
let response = await fetch(`${url}${path}`)
let k = await response.clone()
k = await k.json()
// make directory with k[n].name
if (k.download_url) {
// git doesn't provides the mime type,
// so we implicityly download again from url.
// this way gives only the file, so mime is right.
k.file = await fetch(k.download_url)
k.file = await k.file.blob()
// console.log("file",k)
return k
}
k.directory = k.map(p=>p.name)
// console.log("dir",k)
return k
}


async function LTbrowseOnGitHub(path = ""){
path = path.replace(">","/")
let res = await browseOnGitHub(path)
return res
}

browse = browseOnGitHub
</script>
<script src="files.js"></script>
</body>
</html>

0 comments on commit a829198

Please sign in to comment.