Skip to content

Commit

Permalink
feat: switch backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsuk1ko committed Aug 17, 2024
1 parent ebc9a7d commit 9302476
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 11 deletions.
63 changes: 53 additions & 10 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@
<p class="text-center">
GitHub: <a href="https://github.com/arkntools/maa-resource-updater" target="_blank">arkntools/maa-resource-updater</a>
</p>
<p>Tips 首次使用:如果你本地的资源已经最新,那么可以直接点击“仅 clone / pull”,后续有更新时再用增量更新即可</p>
<p>Tips:由于是白嫖的服务所以你很可能需要挂代理不然 clone 的时候蜗牛爬</p>
<p>
<b>Tips<sup>首次使用</sup></b
>:如果你本地的资源已经最新,那么可以直接点击<span class="proper-name">进阶功能</span>中的<span class="proper-name"
>仅 clone / pull</span
>,后续有更新时再用增量更新即可
</p>
<p>
<b>Tips</b>:由于是白嫖的服务所以你可能 clone 的时候很慢,可以尝试在<span class="proper-name">进阶功能</span>中更改<span
class="proper-name"
>后端</span
>,或者挂代理
</p>
<table class="actions-table">
<tr>
<td class="step">1.</td>
Expand All @@ -24,18 +34,28 @@
<td class="actions">
<button @click="startUpdate" :disabled="!dirHandle || isProcessing">开始更新</button>
<span class="input-group">
<input type="radio" id="update-type-full" value="full" v-model="updateType" />
<input type="radio" id="update-type-full" value="full" :disabled="isProcessing" v-model="updateType" />
<label for="update-type-full">全量更新</label>
</span>
<span class="input-group">
<input type="radio" id="update-type-increment" value="increment" :disabled="!commitList.length" v-model="updateType" />
<input
type="radio"
id="update-type-increment"
value="increment"
:disabled="!commitList.length || isProcessing"
v-model="updateType"
/>
<label for="update-type-increment">增量更新</label>
</span>
<span class="input-group" title="没事别动(">
<input type="checkbox" id="edit-start-commit" :disabled="!commitList.length" v-model="editStartCommit" />
<input type="checkbox" id="edit-start-commit" :disabled="!commitList.length || isProcessing" v-model="editStartCommit" />
<label for="edit-start-commit">更改增量起始 commit</label>
</span>
<select v-model="startCommit" :disabled="!commitList.length || !editStartCommit" style="font-family: monospace; width: 100%">
<select
v-model="startCommit"
:disabled="!commitList.length || !editStartCommit || isProcessing"
style="font-family: monospace; width: 100%"
>
<option v-for="{ message, sha1 } in commitList" :key="sha1" :value="sha1">[{{ sha1.substring(0, 7) }}] {{ message }}</option>
</select>
</td>
Expand All @@ -45,6 +65,12 @@
<td class="actions">
<button @click="gitCloneOrPullOnly" :disabled="isProcessing">仅 clone / pull</button>
<button @click="gitClear" :disabled="isProcessing">清除 git 数据</button>
<span class="input-group">
<label for="git-cors-server" style="margin-right: 8px">后端</label>
<select id="git-cors-server" v-model="gitCORSServer" :disabled="isProcessing">
<option v-for="name in Object.keys(gitCORS)" :key="name" :value="name">{{ name }}</option>
</select>
</span>
</td>
</tr>
</table>
Expand All @@ -56,12 +82,13 @@
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { ref, watch } from 'vue';
import { proxy } from 'comlink';
import { useLocalStorage } from '@vueuse/core';
import { checkIsMAARoot, useDirectoryPicker } from './utils/fileSystem';
import { createGitClient } from './utils/git';
import type { GitCommit, GitProgress } from './workers/git';
import { gitCORS, type GitCORS } from './utils/gitCORS';
const isProcessing = ref(false);
const errorText = ref('');
Expand All @@ -70,6 +97,7 @@ const updateType = useLocalStorage<'full' | 'increment'>('updateType', 'full');
const startCommit = useLocalStorage('startCommit', '');
const editStartCommit = ref(false);
const commitList = ref<GitCommit[]>([]);
const gitCORSServer = useLocalStorage<GitCORS>('gitCORSServer', 'HuggingFace');
const { dirHandle, pickDir } = useDirectoryPicker();
Expand Down Expand Up @@ -103,9 +131,15 @@ const gitClientPromise = createGitClient(
}),
);
gitClientPromise.then(git => {
(window as any).git = git;
});
watch(
gitCORSServer,
async name => {
console.log('set', name);
const git = await gitClientPromise;
await git.setCORSProxy(name);
},
{ immediate: true },
);
const beforeProcessing = () => {
isProcessing.value = true;
Expand Down Expand Up @@ -214,4 +248,13 @@ const gitClear = async () => {
color: red;
margin: 16px 0 0;
}
.proper-name {
white-space: nowrap;
&::before {
content: '';
}
&::after {
content: '';
}
}
</style>
11 changes: 11 additions & 0 deletions src/utils/gitCORS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const gitCORS = import.meta.env.DEV
? {
HuggingFace: 'http://127.0.0.1:9999',
CloudflareWorker: 'http://127.0.0.1:8787',
}
: {
HuggingFace: 'https://mashir0-mrugcp.hf.space',
CloudflareWorker: 'https://mrugcp.lolicon.app',
};

export type GitCORS = keyof typeof gitCORS;
7 changes: 6 additions & 1 deletion src/workers/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import http from 'isomorphic-git/http/web';
import git, { TREE, WORKDIR, type WalkerEntry } from 'isomorphic-git';
import { Buffer } from 'buffer/';
import { PromisePool } from '@supercharge/promise-pool';
import { gitCORS, type GitCORS } from '@/utils/gitCORS';

(globalThis as any).Buffer = Buffer;

Expand Down Expand Up @@ -46,7 +47,7 @@ export class Git {
fs: this.fs,
http,
dir: '/',
corsProxy: import.meta.env.DEV ? 'http://127.0.0.1:9999' : 'https://mashir0-mrugcp.hf.space',
corsProxy: gitCORS.HuggingFace,
url,
singleBranch: true,
depth: 1,
Expand All @@ -64,6 +65,10 @@ export class Git {
this.emitUpdateCommits();
}

setCORSProxy(name: GitCORS) {
this.commonOptions.corsProxy = gitCORS[name];
}

async update() {
let type = '';
if (await this.getHeadCommit()) {
Expand Down

0 comments on commit 9302476

Please sign in to comment.