如何检查一个 Scratch 项目是否通过其 ID 共享?

How do you check if a Scratch project is shared by its ID?

我不希望很多人知道这一点,但是有没有办法检查 Scratch 项目 ID 是否属于共享项目?例如,项目 ID 3 是一个实际项目,但未共享 - 而 ID 399293697 是共享的。那么如何使用 JavaScript 查看这些是否共享?

我搜索了 wiki article about the Scratch API,但没有帮助。 那里提到的唯一有用的端点需要您知道项目的所有者。

通过试验,我发现这些端点有效。

第一个 returns HTTP 404(未找到),第二个 HTTP 200(正常)以及有关项目的详细信息。

备注:

  • 我认为没有办法区分非共享项目和不存在的项目;他们都产生 404.
  • 由于 same-origin policy. On your own browser, you could temporarily turn that off. For a more structural solution, use a CORS proxy.
  • ,我认为您无法在 Web 浏览器中从 JavaScript 运行 直接访问这些端点

下面是一个 JavaScript 示例,用于测试单个项目 ID 是否存在。它使用 yacdn.org, one of the many free CORS proxies.

这只是概念验证。我不能保证它适用于大量查询;许多免费代理会限制您的流量。托管您自己的代理可能更好。

function TestProjectId() {
    const id = document.getElementById('projectId').value;
    const url = 'https://yacdn.org/proxy/https://api.scratch.mit.edu/projects/' + id;
    fetch(url, {method: 'HEAD'})
        .then(response => { document.getElementById('answer').innerHTML = response.ok; });
}
<input type="text" id="projectId" value="399293697" />
<button onclick="TestProjectId()">Test it!</button>
<div id="answer">(answer will appear here)</div>