Skip to content

Commit 151b0ac

Browse files
committed
适配ZeroCat社区
1 parent b7b3570 commit 151b0ac

File tree

11 files changed

+61
-11
lines changed

11 files changed

+61
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"prune": "./prune-gh-pages.sh",
1919
"i18n:push": "tx-push-src scratch-editor interface translations/en.json",
2020
"i18n:src": "rimraf ./translations/messages/src && babel src > tmp.js && rimraf tmp.js && build-i18n-src ./translations/messages/src ./translations/",
21-
"start": "webpack-dev-server",
21+
"start": "ZEROCAT_BACKEND=http://localhost:3000 ZEROCAT_ASSETS=https://zerocat-bitiful.houlangs.com/material/asset webpack-dev-server",
2222
"test": "npm run test:lint && npm run test:unit && npm run build && npm run test:integration",
2323
"test:integration": "jest --maxWorkers=4 test[\\\\/]integration",
2424
"test:lint": "eslint . --ext .js,.jsx",

src/components/menu-bar/menu-bar.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ class MenuBar extends React.Component {
340340
if (modifier) {
341341
if (event.key.toLowerCase() === 's') {
342342
this.props.handleSaveProject();
343-
event.preventDefault();
343+
event.preventDefault();
344344
} else if (event.key.toLowerCase() === 'o') {
345-
event.preventDefault();
345+
event.preventDefault();
346346
this.props.onStartSelectingFileUpload();
347347
}
348348
}
@@ -1031,6 +1031,9 @@ class MenuBar extends React.Component {
10311031
</Button>
10321032
</a>
10331033
</div>
1034+
<div className={styles.menuBarItem}>
1035+
<Button id="zerocattool">ZeroCat服务加载中</Button>
1036+
</div>
10341037
</div>
10351038

10361039
<div className={styles.accountInfoGroup}>

src/containers/extension-library.jsx

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,52 @@ const translateGalleryItem = (extension, locale) => ({
4242
let cachedGallery = null;
4343

4444
const fetchLibrary = async () => {
45-
const res = await fetch('https://extensions.turbowarp.org/generated-metadata/extensions-v0.json');
45+
const res = await fetch(process.env.ZEROCAT_BACKEND + '/extensions');
4646
if (!res.ok) {
4747
throw new Error(`HTTP status ${res.status}`);
4848
}
4949
const data = await res.json();
50-
return data.extensions.map(extension => ({
50+
const extensions = data.extensions.map(extension => ({
51+
name: extension.name,
52+
nameTranslations: extension.nameTranslations || {},
53+
description: extension.description,
54+
descriptionTranslations: extension.descriptionTranslations || {},
55+
extensionId: extension.id,
56+
extensionURL: `${process.env.ZEROCAT_BACKEND}/extensions/${extension.slug}.js`,
57+
iconURL: extension.image,
58+
tags: ['zerocat'],
59+
credits: [
60+
...(extension.original || []),
61+
...(extension.by || [])
62+
].map(credit => {
63+
if (credit.link) {
64+
return (
65+
<a
66+
href={credit.link}
67+
target="_blank"
68+
rel="noreferrer"
69+
key={credit.name}
70+
>
71+
{credit.name}
72+
</a>
73+
);
74+
}
75+
return credit.name;
76+
}),
77+
docsURI: extension.docs ? `${process.env.ZEROCAT_BACKEND}/extensions/${extension.slug}` : null,
78+
samples: extension.samples ? extension.samples.map(sample => ({
79+
href: `${process.env.ROOT}editor?project_url=${process.env.ZEROCAT_BACKEND}/extensions/samples/${encodeURIComponent(sample)}.sb3`,
80+
text: sample
81+
})) : null,
82+
incompatibleWithScratch: !extension.scratchCompatible,
83+
featured: true
84+
}));
85+
const twRes = await fetch('https://extensions.turbowarp.org/generated-metadata/extensions-v0.json');
86+
if (!twRes.ok) {
87+
throw new Error(`HTTP status ${twRes.status}`);
88+
}
89+
const twData = await twRes.json();
90+
const twExtensions = twData.extensions.map(extension => ({
5191
name: extension.name,
5292
nameTranslations: extension.nameTranslations || {},
5393
description: extension.description,
@@ -82,6 +122,7 @@ const fetchLibrary = async () => {
82122
incompatibleWithScratch: !extension.scratchCompatible,
83123
featured: true
84124
}));
125+
return [...extensions, ...twExtensions];
85126
};
86127

87128
class ExtensionLibrary extends React.PureComponent {

src/containers/library-item.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class LibraryItem extends React.PureComponent {
139139
render () {
140140
const iconMd5 = this.curIconMd5();
141141
const iconURL = iconMd5 ?
142-
`https://cdn.assets.scratch.mit.edu/internalapi/asset/${iconMd5}/get/` :
142+
`${process.env.ZEROCAT_ASSETS}/${iconMd5}` :
143143
this.props.iconRawURL;
144144
return (
145145
<LibraryItemComponent

src/containers/tw-security-manager.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const manuallyTrustExtension = url => {
2626
const isTrustedExtension = url => (
2727
// Always trust our official extension repostiory.
2828
url.startsWith('https://extensions.turbowarp.org/') ||
29-
29+
// Always trust ZeroCat official extension repostiory.
30+
url.startsWith(process.env.ZEROCAT_BACKEND + '/extensions/') ||
3031
// For development.
3132
url.startsWith('http://localhost:8000/') ||
3233

src/lib/libraries/tw-extension-tags.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import {APP_NAME} from '../brand';
33
// Because there are all brand names, it is unnecessary for them to be translatable.
44
export default [
55
{tag: 'scratch', intlLabel: 'Scratch'},
6-
{tag: 'tw', intlLabel: APP_NAME}
6+
{tag: 'zerocat', intlLabel: 'ZeroCat'},
7+
{tag: 'tw', intlLabel: APP_NAME},
78
];

src/lib/project-fetcher-hoc.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ const ProjectFetcherHOC = function (WrappedComponent) {
198198
vm: PropTypes.instanceOf(VM)
199199
};
200200
ProjectFetcherComponent.defaultProps = {
201-
assetHost: 'https://assets.scratch.mit.edu',
201+
assetHost: process.env.ZEROCAT_ASSETS,
202202
projectHost: 'https://projects.scratch.mit.edu'
203203
};
204204

src/lib/storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Storage extends ScratchStorage {
5555
this.assetHost = assetHost;
5656
}
5757
getAssetGetConfig (asset) {
58-
return `${this.assetHost}/internalapi/asset/${asset.assetId}.${asset.dataFormat}/get/`;
58+
return `${this.assetHost}/${asset.assetId}.${asset.dataFormat}`;
5959
}
6060
getAssetCreateConfig (asset) {
6161
return {

src/playground/embed.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66
<meta name="google" value="notranslate">
77
<title><%= htmlWebpackPlugin.options.title %></title>
8+
<script src="<%= process.env.ZEROCAT_BACKEND %>/scratchtool"></script>
89
<style>
910
.splash-screen {
1011
position: absolute;

src/playground/index.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta name="google" value="notranslate">
77
<meta name="description" content="<%= htmlWebpackPlugin.options.APP_NAME %> is a Scratch mod with a compiler to run projects faster, dark mode for your eyes, a bunch of addons to improve the editor, and more." />
88
<title><%= htmlWebpackPlugin.options.title %></title>
9+
<script src="<%= process.env.ZEROCAT_BACKEND %>/scratchtool"></script>
910
<link rel="apple-touch-icon" href="<%= htmlWebpackPlugin.options.root %>images/apple-touch-icon.png">
1011
<% if (htmlWebpackPlugin.options.root === "/" || htmlWebpackPlugin.options.root === "") { %>
1112
<link rel="manifest" href="<%= htmlWebpackPlugin.options.root %>manifest.webmanifest">

0 commit comments

Comments
 (0)