-
-
Save astrolemonade/d65cc03523f2fb197dddc2b924cf3916 to your computer and use it in GitHub Desktop.
Revisions
-
jamiephan revised this gist
Sep 17, 2024 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ (await (async (startPage = 0, autoClearConsole = true) => { const getCookie = (name) => { const value = `; ${document.cookie}`; @@ -76,6 +77,7 @@ await Promise.all(aclPromises) console.log("-> ======================= PAGE " + pageIdx + " COMPLETED =======================") if (autoClearConsole) console.clear() // Fix the issue that too much log hangs the console. Set autoClearConsole = false to keep the logs } })()) -
jamiephan revised this gist
Sep 17, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,6 +20,7 @@ As quixel is being removed, all items are free to aquire. This script is to auto - There is a chance that the API adding too fast and you hit the rate limit of the API. (My testing is around after 10 pages, so ~10k items). - Wait after ~10-20 minutes and continue. See `Common Fixes -> Restart script` to continue the execution after you can load https://quixel.com. - The script seems to be paused/hang - It could be too much logging going it. Try monitor the script, if it says "END PAGE X", note the page number down (in case need restart) and clear the console by clicking the "🚫" icon in devtools. - See `Common Fixes -> Restart script` for fixing. - Getting the error `**UNABLE TO ADD ITEM**` - There should have the error message shown in `( )`. If it is `user already owns specified asset at a higher or equal resolution`, then its already in your account. -
jamiephan revised this gist
Sep 17, 2024 . No changes.There are no files selected for viewing
-
jamiephan revised this gist
Sep 17, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ As quixel is being removed, all items are free to aquire. This script is to auto ### How to use 1. Copy the script from below (`run.js`) 2. Login into https://quixel.com 3. Go to https://quixel.com/megascans/collections 4. Open devtools (F12) -> Go to "Console" tab -
jamiephan created this gist
Sep 17, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ ## Script to add all items from [quixel](https://quixel.com/) As quixel is being removed, all items are free to aquire. This script is to automate the process to add items to your account (As of writing, a total of `18874` items) >Note: This script only tested in the latest version of Chrome. ### How to use 1. Copy the script below (`run.js`) 2. Login into https://quixel.com 3. Go to https://quixel.com/megascans/collections 4. Open devtools (F12) -> Go to "Console" tab 5. Paste in the script and press <kbd>Enter</kbd>. 6. A dialog should popup confirming the execution, click "OK" 7. Sit back and wait ### Common issues - Getting "Forbidden" error. (Even after refresh, the whole page just shows "Forbidden") - There is a chance that the API adding too fast and you hit the rate limit of the API. (My testing is around after 10 pages, so ~10k items). - Wait after ~10-20 minutes and continue. See `Common Fixes -> Restart script` to continue the execution after you can load https://quixel.com. - The script seems to be paused/hang - See `Common Fixes -> Restart script` for fixing. - Getting the error `**UNABLE TO ADD ITEM**` - There should have the error message shown in `( )`. If it is `user already owns specified asset at a higher or equal resolution`, then its already in your account. - Getting the error `cannot find authentication token. Please login again` - Clear browser cookies and re-login quixel again. Try just simply add 1 item manully. If it success, then see `Common Fixes -> Restart script` for continue the execution. ### Common Fixes #### Restart Script 1. If it hang too long, note what page is had going (Search for log like `PAGE 10 START`) 2. Copy the `run.js` script 3. Update the `startPage = 0` on the first line to `startPage = 10` (assuming page 10 was hanged) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ (await (async (startPage = 0) => { const getCookie = (name) => { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); } const callCacheApi = async (params = {}) => { const defaultParams = { page: 0, maxValuesPerFacet: 1000, hitsPerPage: 1000, attributesToRetrieve: ["id", "name"].join(",") } const response = await fetch("https://proxy-algolia-prod.quixel.com/algolia/cache", { "headers": { "x-api-key": "2Zg8!d2WAHIUW?pCO28cVjfOt9seOWPx@2j" }, "body": JSON.stringify({ url: "https://6UJ1I5A072-2.algolianet.com/1/indexes/assets/query?x-algolia-application-id=6UJ1I5A072&x-algolia-api-key=e93907f4f65fb1d9f813957bdc344892", params: new URLSearchParams({ ...defaultParams, ...params }).toString() }), "method": "POST", }) return await response.json() } const callAcl = async ({ id, name }) => { console.log(` --> Adding Item ${id} | ${name}...`) const response = await fetch("https://quixel.com/v1/acl", { "headers": { "authorization": "Bearer " + authToken, "content-type": "application/json;charset=UTF-8", }, "body": JSON.stringify({ assetID: id }), "method": "POST", }); const json = await response.json() if (json?.isError) { console.error(` --> **UNABLE TO ADD ITEM** Item ${id} | ${name} (${json?.msg})`) } else { console.log(` --> ADDED ITEM Item ${id} | ${name}`) } } // 1. Check token exist, quixel API needs it console.log("-> Checking Auth API Token...") let authToken = "" try { const authCookie = getCookie("auth") ?? "{}" authToken = JSON.parse(decodeURIComponent(authCookie))?.token if (!authToken) { return console.error("-> Error: cannot find authentication token. Please login again.") } } catch (_) { return console.error("-> Error: cannot find authentication token. Please login again.") } // 2. Get total count of items console.log("-> Getting Total Number of Pages....") const { nbPages: totalPages, hitsPerPage: itemsPerPage, nbHits: totalItems } = await callCacheApi() console.log(`-> Total Items to add: ${totalItems} | ${totalPages} total pages with ${itemsPerPage} per page`) if (!confirm(`Click OK to start adding ${totalItems} items in your account.`)) return // Loop for (let pageIdx = startPage || 0; pageIdx < totalPages; pageIdx++) { console.log("-> ======================= PAGE " + pageIdx + " START =======================") console.log("-> Getting Items from page " + pageIdx + " ...") const { hits: items } = await callCacheApi({ page: pageIdx }) const aclPromises = items.map(callAcl) await Promise.all(aclPromises) console.log("-> ======================= PAGE " + pageIdx + " COMPLETED =======================") } })())