-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ignacio Mazzara <[email protected]>
- Loading branch information
1 parent
e4ac0c1
commit 7f8e487
Showing
1 changed file
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Coordinate Checker</title> | ||
<style> | ||
body { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
margin: 0; | ||
overflow-y: auto; | ||
} | ||
|
||
#appContainer { | ||
text-align: center; | ||
padding: 20px; | ||
border: 1px solid #ccc; | ||
border-radius: 10px; | ||
background-color: #f9f9f9; | ||
} | ||
|
||
#coordinatesInput { | ||
width: 600px; | ||
margin-bottom: 10px; | ||
padding: 10px; | ||
box-sizing: border-box; | ||
} | ||
|
||
button { | ||
width: 100%; | ||
max-width: 600px; | ||
padding: 10px; | ||
box-sizing: border-box; | ||
margin-bottom: 20px; | ||
} | ||
|
||
p.log-entry { | ||
width: 600px; | ||
margin: 10px auto; | ||
word-break: break-word; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="appContainer"> | ||
<h3>Enter Coordinates:</h3> | ||
<input type="text" id="coordinatesInput" placeholder="e.g. -12,34; 56,-78; 9,0"> | ||
<button onclick="validateInput()">Check</button> | ||
<div id="coordinateContainer"></div> | ||
|
||
</div> | ||
|
||
<script> | ||
const abServer = 'https://ab-cdn.decentraland.org' | ||
const contentServer = 'https://peer.decentraland.org/content' | ||
|
||
function validateInput() { | ||
const input = document.getElementById('coordinatesInput').value | ||
// Split the input string by ';' to get individual coordinate pairs | ||
const coordinatePairs = input.split(';').map(pair => pair.trim()) | ||
|
||
const validCoordinates = [] | ||
let isValid = true | ||
|
||
// Validate each coordinate pair | ||
coordinatePairs.forEach(pair => { | ||
const coordinates = pair.split(',').map(coord => coord.trim()) | ||
if (coordinates.length === 2) { | ||
const [x, y] = coordinates | ||
if (!isNaN(x) && !isNaN(y)) { | ||
validCoordinates.push(`${parseFloat(x)},${parseFloat(y)}`) | ||
} else { | ||
console.log(`Invalid coordinates: (${x}, ${y})`) | ||
isValid = false | ||
} | ||
} else { | ||
console.log(`Invalid format: ${pair}`) | ||
isValid = false | ||
} | ||
}) | ||
|
||
if (isValid) { | ||
checkCoordinates(validCoordinates) | ||
} | ||
} | ||
|
||
async function checkCoordinates(coordinateArray) { | ||
const container = document.getElementById('coordinateContainer') | ||
container.innerHTML = '' | ||
|
||
// Add loading message | ||
const loadingMessage = document.createElement('p') | ||
loadingMessage.textContent = 'Loading...' | ||
container.appendChild(loadingMessage) | ||
|
||
const entityIdsToConvert = [] | ||
for (const entity of await getActiveEntities(coordinateArray, contentServer)) { | ||
entityIdsToConvert.push({ entityId: entity.id, pointers: entity.pointers }) | ||
} | ||
console.log(entityIdsToConvert) | ||
|
||
for (const { entityId, pointers } of entityIdsToConvert) { | ||
appendLog(container, 'Pointers\n' + pointers.join(' ; ')) | ||
const result = await fetch(`${abServer}/manifest/${entityId}.json`) | ||
const resultWindows = await fetch(`${abServer}/manifest/${entityId}_windows.json`) | ||
const resultMac = await fetch(`${abServer}/manifest/${entityId}_mac.json`) | ||
|
||
appendLog(container, 'WEBGL') | ||
await check(entityId, pointers, result) | ||
|
||
appendLog(container, 'WINDOWS') | ||
await check(entityId, pointers, resultWindows) | ||
|
||
appendLog(container, 'MAC') | ||
await check(entityId, pointers, resultMac) | ||
|
||
appendLog(container, '') | ||
appendLog(container, '-----------------------------------------------------------------------------------') | ||
appendLog(container, '') | ||
} | ||
|
||
// Remove loading message | ||
container.removeChild(loadingMessage) | ||
console.log(`Finished!`) | ||
} | ||
|
||
async function getActiveEntities(pointers, sourceServer) { | ||
const url = `${sourceServer}/entities/active` | ||
const res = await fetch(url, { | ||
method: 'post', | ||
body: JSON.stringify({ pointers }), | ||
headers: { 'content-type': 'application/json' } | ||
}) | ||
|
||
const response = await res.text() | ||
|
||
if (!res.ok) { | ||
throw new Error('Error fetching list of active entities: ' + response) | ||
} | ||
|
||
return JSON.parse(response) | ||
} | ||
|
||
async function check(entityId, pointers, promise) { | ||
const container = document.getElementById('coordinateContainer') | ||
if (!promise.ok) { | ||
const failManifest = await fetch(`${abServer}/manifest/${entityId}_failed.json`) // Mock URL for the example | ||
if (failManifest.ok) { | ||
const manifest = await failManifest.json() | ||
const logMessage = `🟠 ${entityId} (${pointers[0]}): Failed. Version=${manifest.version} ExitCode=${manifest.exitCode} Date=${manifest.date} Log=${manifest.log}` | ||
appendLog(container, logMessage) | ||
} else { | ||
const logMessage = `🔴 ${entityId} (${pointers[0]}): Not converted!` | ||
appendLog(container, logMessage) | ||
} | ||
} else { | ||
const manifest = await promise.json() | ||
const logMessage = `🟢 ${entityId} (${pointers[0]}): Version=${manifest.version} ExitCode=${manifest.exitCode} Date=${manifest.date}` | ||
appendLog(container, logMessage) | ||
} | ||
} | ||
|
||
function appendLog(container, message) { | ||
const logP = document.createElement('p') | ||
logP.className = 'log-entry' | ||
logP.textContent = message | ||
container.appendChild(logP) | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> |