-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
49 lines (43 loc) · 1.82 KB
/
App.js
File metadata and controls
49 lines (43 loc) · 1.82 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from "react";
import Login from "./Login";
import OpenLink from "./OpenLink";
import { Alert } from "react-native";
export default function Chocolate() {
const [url, setURL] = React.useState()
const [work, setWork] = React.useState(false)
console.log(url)
function loadChocolate() {
const regexExpurl = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/;
const regexExpIP = /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\:?([0-9]{1,5})?/
let regexWork = false;
let isChocolate = false;
let tempURL = url
if (tempURL.startsWith("http://") || tempURL.startsWith("https://")) {
tempURL = tempURL.replace("https://", "").replace("http://", "")
}
checkURL = `http://${tempURL}/isChocolate`
if (regexExpurl.test(tempURL) || regexExpIP.test(tempURL)) {
regexWork = true;
console.log("fetch -1")
fetch(checkURL).then(response => { console.log("response"+response); return response.json(); }).then(data => {
if (data.isChocolate) {
isChocolate = true;
} else {
Alert.alert("Chocolate", "This is not a Chocolate Server")
isChocolate = false;
}}).then(() => {
if (regexWork && isChocolate) {
setWork(true)
}}).catch((error) => {
Alert.alert("Chocolate Server Error", "This is not a Chocolate Server")
})
} else {
Alert.alert("Chocolate URL Error", "This is not a valid URL")
}
}
return (
<>
{!work ? <Login setURL={setURL} loadChocolate={loadChocolate} /> : <OpenLink url={url} />}
</>
);
}