Compare commits
	
		
			7 Commits
		
	
	
		
			v0.0.1-pre
			...
			master
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						128cdcee52
	
				 | 
					
					
						|||
| 
						
						
							
						
						5a9e73d4f2
	
				 | 
					
					
						|||
| 
						
						
							
						
						a77942621e
	
				 | 
					
					
						|||
| 
						
						
							
						
						e032f86503
	
				 | 
					
					
						|||
| 
						
						
							
						
						3c6d8df6d6
	
				 | 
					
					
						|||
| 
						
						
							
						
						2fdff3cb33
	
				 | 
					
					
						|||
| 
						
						
							
						
						13b303ea3f
	
				 | 
					
					
						
							
								
								
									
										14
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						@@ -18,7 +18,15 @@ jobs:
 | 
				
			|||||||
        uses: actions/checkout@v3
 | 
					        uses: actions/checkout@v3
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          fetch-depth: 0
 | 
					          fetch-depth: 0
 | 
				
			||||||
 | 
					      - name: Setup NodeJS
 | 
				
			||||||
 | 
					        uses: actions/setup-node@v3
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          node-version: '18.x'
 | 
				
			||||||
 | 
					          cache: 'yarn'
 | 
				
			||||||
 | 
					          cache-dependency-path: frontend
 | 
				
			||||||
 | 
					      - name: Build Frontend
 | 
				
			||||||
 | 
					        run: |
 | 
				
			||||||
 | 
					          make assets
 | 
				
			||||||
      - name: Build Yggdrasil Server
 | 
					      - name: Build Yggdrasil Server
 | 
				
			||||||
        uses: crazy-max/ghaction-xgo@v2
 | 
					        uses: crazy-max/ghaction-xgo@v2
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
@@ -37,14 +45,14 @@ jobs:
 | 
				
			|||||||
      - name: Create ZIP archive
 | 
					      - name: Create ZIP archive
 | 
				
			||||||
        if: startsWith(github.ref, 'refs/tags/')
 | 
					        if: startsWith(github.ref, 'refs/tags/')
 | 
				
			||||||
        run: |
 | 
					        run: |
 | 
				
			||||||
          cp -v ./config_example.ini ./build || exit 1
 | 
					          cp -v ./config_example.ini ./assets ./build/ || exit 1
 | 
				
			||||||
          pushd build || exit 1
 | 
					          pushd build || exit 1
 | 
				
			||||||
          ls -1 yggdrasil-* | while read LINE; do
 | 
					          ls -1 yggdrasil-* | while read LINE; do
 | 
				
			||||||
          PREFIX="${LINE%.*}"
 | 
					          PREFIX="${LINE%.*}"
 | 
				
			||||||
          SUFFIX="$(echo "$LINE" | grep -osE '\.\w+' || printf '')"
 | 
					          SUFFIX="$(echo "$LINE" | grep -osE '\.\w+' || printf '')"
 | 
				
			||||||
          cp -v "$LINE" "yggdrasil$SUFFIX"
 | 
					          cp -v "$LINE" "yggdrasil$SUFFIX"
 | 
				
			||||||
          FILE="../$PREFIX.zip"
 | 
					          FILE="../$PREFIX.zip"
 | 
				
			||||||
          zip -9v "$FILE" "yggdrasil$SUFFIX" *.ini
 | 
					          zip -9v "$FILE" "yggdrasil$SUFFIX" *.ini assets
 | 
				
			||||||
          DGST="$FILE.dgst"
 | 
					          DGST="$FILE.dgst"
 | 
				
			||||||
          openssl dgst -md5    "$FILE" | sed 's/([^)]*)//g' >>"$DGST"
 | 
					          openssl dgst -md5    "$FILE" | sed 's/([^)]*)//g' >>"$DGST"
 | 
				
			||||||
          openssl dgst -sha1   "$FILE" | sed 's/([^)]*)//g' >>"$DGST"
 | 
					          openssl dgst -sha1   "$FILE" | sed 's/([^)]*)//g' >>"$DGST"
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						@@ -19,6 +19,7 @@
 | 
				
			|||||||
# Dependency directories (remove the comment below to include it)
 | 
					# Dependency directories (remove the comment below to include it)
 | 
				
			||||||
# vendor/
 | 
					# vendor/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					assets
 | 
				
			||||||
yggdrasil
 | 
					yggdrasil
 | 
				
			||||||
/*.pem
 | 
					/*.pem
 | 
				
			||||||
/*.db
 | 
					/*.db
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,6 +10,7 @@ COPY "build/yggdrasil-${TARGETOS}-${TARGETARCH}" /app/yggdrasil
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
EXPOSE 8080
 | 
					EXPOSE 8080
 | 
				
			||||||
VOLUME /app/data
 | 
					VOLUME /app/data
 | 
				
			||||||
 | 
					COPY assets /app/data/assets/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WORKDIR /app/data
 | 
					WORKDIR /app/data
 | 
				
			||||||
ENTRYPOINT ["/app/yggdrasil"]
 | 
					ENTRYPOINT ["/app/yggdrasil"]
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						@@ -10,14 +10,20 @@ PACKAGE_NAME = yggdrasil.tar.gz
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
default: $(BINARY)
 | 
					default: $(BINARY)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(BINARY):
 | 
					$(BINARY):assets
 | 
				
			||||||
	$(GO_BUILD) -tags='nomsgpack,sqlite,mysql' -o $(BINARY)
 | 
						$(GO_BUILD) -tags='nomsgpack,sqlite,mysql' -o $(BINARY)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
get:
 | 
					get:
 | 
				
			||||||
	$(GO_GET)
 | 
						$(GO_GET)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					assets:
 | 
				
			||||||
 | 
						mkdir -p assets
 | 
				
			||||||
 | 
						yarn --cwd frontend install --frozen-lockfile --non-interactive
 | 
				
			||||||
 | 
						yarn --cwd frontend build
 | 
				
			||||||
 | 
						cp -r frontend/dist/. assets/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package:$(BINARY)
 | 
					package:$(BINARY)
 | 
				
			||||||
	tar -zcf $(PACKAGE_NAME) $(BINARY) config_example.ini
 | 
						tar -zcf $(PACKAGE_NAME) $(BINARY) config_example.ini assets
 | 
				
			||||||
 | 
					
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	-$(GO_CLEAN)
 | 
						-$(GO_CLEAN)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,7 +24,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
启动成功后在启动器(请使用第三方启动器)外置登录选项上填写运行的 URL 的根路径,比如 `http://localhost:8080`。
 | 
					启动成功后在启动器(请使用第三方启动器)外置登录选项上填写运行的 URL 的根路径,比如 `http://localhost:8080`。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
注册地址在 `/profile/index.html`。
 | 
					注册地址在 `/profile/`。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Docker
 | 
					## Docker
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,86 +0,0 @@
 | 
				
			|||||||
<!--
 | 
					 | 
				
			||||||
  ~ Copyright (C) 2022. Gardel <sunxinao@hotmail.com> and contributors
 | 
					 | 
				
			||||||
  ~
 | 
					 | 
				
			||||||
  ~ This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
  ~ it under the terms of the GNU Affero General Public License as published by
 | 
					 | 
				
			||||||
  ~ the Free Software Foundation, either version 3 of the License, or
 | 
					 | 
				
			||||||
  ~ (at your option) any later version.
 | 
					 | 
				
			||||||
  ~
 | 
					 | 
				
			||||||
  ~ This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
  ~ GNU Affero General Public License for more details.
 | 
					 | 
				
			||||||
  ~
 | 
					 | 
				
			||||||
  ~ You should have received a copy of the GNU Affero General Public License
 | 
					 | 
				
			||||||
  ~ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
  -->
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<!doctype html>
 | 
					 | 
				
			||||||
<html lang="en">
 | 
					 | 
				
			||||||
<head>
 | 
					 | 
				
			||||||
  <meta charset="utf-8">
 | 
					 | 
				
			||||||
  <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
					 | 
				
			||||||
  <title>注册</title>
 | 
					 | 
				
			||||||
  <link rel="stylesheet" href="https://cdn.bootcss.com/normalize/8.0.0/normalize.min.css">
 | 
					 | 
				
			||||||
  <!-- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700"> -->
 | 
					 | 
				
			||||||
  <link href="https://cdn.bootcss.com/material-components-web/5.1.0/material-components-web.min.css" rel="stylesheet">
 | 
					 | 
				
			||||||
  <script src="https://cdn.bootcss.com/material-components-web/5.1.0/material-components-web.min.js"></script>
 | 
					 | 
				
			||||||
  <link rel="stylesheet" href="login.css">
 | 
					 | 
				
			||||||
</head>
 | 
					 | 
				
			||||||
<body >
 | 
					 | 
				
			||||||
  <noscript>You need to enable JavaScript to run this app.</noscript>
 | 
					 | 
				
			||||||
  <section class="header">
 | 
					 | 
				
			||||||
    <h1>简陋注册页</h1>
 | 
					 | 
				
			||||||
  </section>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <form id="reg-form" action="#">
 | 
					 | 
				
			||||||
    <div class="mdc-text-field username">
 | 
					 | 
				
			||||||
      <input type="email" class="mdc-text-field__input" id="username-input" name="username" required>
 | 
					 | 
				
			||||||
      <label class="mdc-floating-label" for="username-input">邮箱</label>
 | 
					 | 
				
			||||||
      <div class="mdc-line-ripple"></div>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
	<div class="mdc-text-field profileName">
 | 
					 | 
				
			||||||
	  <input type="text" class="mdc-text-field__input" id="profileName-input" name="profileName" required minlength="2">
 | 
					 | 
				
			||||||
	  <label class="mdc-floating-label" for="profileName-input">角色名</label>
 | 
					 | 
				
			||||||
	  <div class="mdc-line-ripple"></div>
 | 
					 | 
				
			||||||
	</div>
 | 
					 | 
				
			||||||
    <div class="mdc-text-field-helper-line profileName-helper">
 | 
					 | 
				
			||||||
      <div class="mdc-text-field-helper-text" aria-hidden="true">字母,数字或下划线</div>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
    <div class="mdc-text-field password">
 | 
					 | 
				
			||||||
      <input type="password" class="mdc-text-field__input" id="password-input" name="password" required minlength="6">
 | 
					 | 
				
			||||||
      <label class="mdc-floating-label" for="password-input">密码</label>
 | 
					 | 
				
			||||||
      <div class="mdc-line-ripple"></div>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
	<div class="mdc-text-field-helper-line password-helper">
 | 
					 | 
				
			||||||
	  <div class="mdc-text-field-helper-text" aria-hidden="true">警告: 暂无重置密码接口,请妥善保管密码</div>
 | 
					 | 
				
			||||||
	</div>
 | 
					 | 
				
			||||||
    <div class="button-container">
 | 
					 | 
				
			||||||
      <button class="mdc-button mdc-button--raised login">
 | 
					 | 
				
			||||||
        <div class="mdc-button__ripple"></div>
 | 
					 | 
				
			||||||
        <span class="mdc-button__label">
 | 
					 | 
				
			||||||
          已有账号登录
 | 
					 | 
				
			||||||
        </span>
 | 
					 | 
				
			||||||
      </button>
 | 
					 | 
				
			||||||
      <button type="submit" class="mdc-button mdc-button--raised next">
 | 
					 | 
				
			||||||
        <div class="mdc-button__ripple"></div>
 | 
					 | 
				
			||||||
        <span class="mdc-button__label">
 | 
					 | 
				
			||||||
          下一步
 | 
					 | 
				
			||||||
        </span>
 | 
					 | 
				
			||||||
      </button>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
  </form>
 | 
					 | 
				
			||||||
  <div class="mdc-snackbar">
 | 
					 | 
				
			||||||
    <div class="mdc-snackbar__surface">
 | 
					 | 
				
			||||||
      <div class="mdc-snackbar__label"
 | 
					 | 
				
			||||||
           role="status"
 | 
					 | 
				
			||||||
           aria-live="polite">
 | 
					 | 
				
			||||||
        注册失败
 | 
					 | 
				
			||||||
      </div>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
  </div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <script src="https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js"></script>
 | 
					 | 
				
			||||||
  <script src="login.js" async></script>
 | 
					 | 
				
			||||||
</body>
 | 
					 | 
				
			||||||
</html>
 | 
					 | 
				
			||||||
							
								
								
									
										129
									
								
								assets/login.js
									
									
									
									
									
								
							
							
						
						@@ -1,129 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2022. Gardel <sunxinao@hotmail.com> and contributors
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU Affero General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
					 | 
				
			||||||
 * (at your option) any later version.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU Affero General Public License for more details.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU Affero General Public License
 | 
					 | 
				
			||||||
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const MDCSnackbar = mdc.snackbar.MDCSnackbar;
 | 
					 | 
				
			||||||
const MDCTextField = mdc.textField.MDCTextField;
 | 
					 | 
				
			||||||
const MDCRipple = mdc.ripple.MDCRipple;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const snackbar = new MDCSnackbar(document.querySelector(".mdc-snackbar"));
 | 
					 | 
				
			||||||
const username = new MDCTextField(document.querySelector(".username"));
 | 
					 | 
				
			||||||
const password = new MDCTextField(document.querySelector(".password"));
 | 
					 | 
				
			||||||
const profileName = new MDCTextField(document.querySelector(".profileName"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
new MDCRipple(document.querySelector(".next"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
snackbar.close();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var login = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$(".login").click(function (btn) {
 | 
					 | 
				
			||||||
    login = true;
 | 
					 | 
				
			||||||
    $(".profileName").hide();
 | 
					 | 
				
			||||||
    $("#profileName-input").removeAttr("required");
 | 
					 | 
				
			||||||
    $(".next").children(".mdc-button__label").text("登录");
 | 
					 | 
				
			||||||
    $(this).hide();
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$("#reg-form").submit(function (e) {
 | 
					 | 
				
			||||||
    if (!login) {
 | 
					 | 
				
			||||||
        $.ajax({
 | 
					 | 
				
			||||||
            url: "/authserver/register",
 | 
					 | 
				
			||||||
            type: "POST",
 | 
					 | 
				
			||||||
            dataType: "JSON",
 | 
					 | 
				
			||||||
            contentType: "application/json",
 | 
					 | 
				
			||||||
            data: JSON.stringify({
 | 
					 | 
				
			||||||
                username: username.value,
 | 
					 | 
				
			||||||
                password: password.value,
 | 
					 | 
				
			||||||
                profileName: profileName.value
 | 
					 | 
				
			||||||
            }),
 | 
					 | 
				
			||||||
            success: function (data) {
 | 
					 | 
				
			||||||
                if (!data.id) {
 | 
					 | 
				
			||||||
                    if (data.errorMessage) snackbar.labelText = data.errorMessage;
 | 
					 | 
				
			||||||
                    snackbar.open();
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    login = true;
 | 
					 | 
				
			||||||
                    $(".profileName").hide();
 | 
					 | 
				
			||||||
                    $(".login").hide();
 | 
					 | 
				
			||||||
                    $(".next").children(".mdc-button__label").text("登录");
 | 
					 | 
				
			||||||
                    snackbar.timeoutMs = 10000;
 | 
					 | 
				
			||||||
                    snackbar.labelText = "注册成功,uid:" + data.id;
 | 
					 | 
				
			||||||
                    snackbar.open();
 | 
					 | 
				
			||||||
                    localStorage.uuid = data.id;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            error: function (e) {
 | 
					 | 
				
			||||||
                let response = JSON.parse(e.responseText);
 | 
					 | 
				
			||||||
                if (response.errorMessage === "profileName exist") {
 | 
					 | 
				
			||||||
                    snackbar.labelText = "注册失败: 角色名已存在";
 | 
					 | 
				
			||||||
                } else if (response.errorMessage === "profileName duplicate") {
 | 
					 | 
				
			||||||
                    snackbar.labelText = "注册失败: 角色名与正版用户冲突";
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    snackbar.labelText = "注册失败: " + response.errorMessage;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                snackbar.open();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        $.ajax({
 | 
					 | 
				
			||||||
            url: "/authserver/authenticate",
 | 
					 | 
				
			||||||
            type: "POST",
 | 
					 | 
				
			||||||
            dataType: "JSON",
 | 
					 | 
				
			||||||
            contentType: "application/json",
 | 
					 | 
				
			||||||
            data: JSON.stringify({
 | 
					 | 
				
			||||||
                username: username.value,
 | 
					 | 
				
			||||||
                password: password.value
 | 
					 | 
				
			||||||
            }),
 | 
					 | 
				
			||||||
            success: function (data) {
 | 
					 | 
				
			||||||
                if (!data.accessToken) {
 | 
					 | 
				
			||||||
                    snackbar.labelText = "登录失败:";
 | 
					 | 
				
			||||||
                    if (data.errorMessage) snackbar.labelText += data.errorMessage;
 | 
					 | 
				
			||||||
                    snackbar.open();
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
                    snackbar.labelText = "登录成功,accessToken:" + data.accessToken;
 | 
					 | 
				
			||||||
                    snackbar.open();
 | 
					 | 
				
			||||||
                    localStorage.accessToken = data.accessToken;
 | 
					 | 
				
			||||||
                    localStorage.loginTime = new Date().getTime();
 | 
					 | 
				
			||||||
                    localStorage.profileName = data.selectedProfile.name;
 | 
					 | 
				
			||||||
                    if (data.selectedProfile) {
 | 
					 | 
				
			||||||
                        localStorage.profileName = data.selectedProfile.name;
 | 
					 | 
				
			||||||
                        localStorage.uuid = data.selectedProfile.id;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    // localStorage.username = username.value;
 | 
					 | 
				
			||||||
                    // localStorage.password = password.value;
 | 
					 | 
				
			||||||
                    setTimeout(function () {
 | 
					 | 
				
			||||||
                        window.location = "user.html";
 | 
					 | 
				
			||||||
                    }, 3000);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            error: function (e) {
 | 
					 | 
				
			||||||
                let response = JSON.parse(e.responseText);
 | 
					 | 
				
			||||||
                snackbar.labelText = "登录失败: " + response.errorMessage;
 | 
					 | 
				
			||||||
                snackbar.open();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    e.preventDefault();
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$(document).ready(function () {
 | 
					 | 
				
			||||||
    if (!localStorage.accessToken && localStorage.loginTime !== undefined &&
 | 
					 | 
				
			||||||
        (new Date().getTime() - localStorage.loginTime) < 30 * 86400 * 1000) {
 | 
					 | 
				
			||||||
        window.location = "user.html";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
							
								
								
									
										154
									
								
								assets/user.html
									
									
									
									
									
								
							
							
						
						@@ -1,154 +0,0 @@
 | 
				
			|||||||
<!--
 | 
					 | 
				
			||||||
  ~ Copyright (C) 2022. Gardel <sunxinao@hotmail.com> and contributors
 | 
					 | 
				
			||||||
  ~
 | 
					 | 
				
			||||||
  ~ This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
  ~ it under the terms of the GNU Affero General Public License as published by
 | 
					 | 
				
			||||||
  ~ the Free Software Foundation, either version 3 of the License, or
 | 
					 | 
				
			||||||
  ~ (at your option) any later version.
 | 
					 | 
				
			||||||
  ~
 | 
					 | 
				
			||||||
  ~ This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
  ~ GNU Affero General Public License for more details.
 | 
					 | 
				
			||||||
  ~
 | 
					 | 
				
			||||||
  ~ You should have received a copy of the GNU Affero General Public License
 | 
					 | 
				
			||||||
  ~ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
  -->
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<!doctype html>
 | 
					 | 
				
			||||||
<html lang="en">
 | 
					 | 
				
			||||||
<head>
 | 
					 | 
				
			||||||
    <meta charset="utf-8">
 | 
					 | 
				
			||||||
    <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
					 | 
				
			||||||
    <title>角色信息</title>
 | 
					 | 
				
			||||||
    <link rel="stylesheet" href="https://cdn.bootcss.com/normalize/8.0.0/normalize.min.css">
 | 
					 | 
				
			||||||
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
 | 
					 | 
				
			||||||
    <link href="https://cdn.bootcss.com/material-components-web/5.1.0/material-components-web.min.css" rel="stylesheet">
 | 
					 | 
				
			||||||
    <script src="https://cdn.bootcss.com/material-components-web/5.1.0/material-components-web.min.js"></script>
 | 
					 | 
				
			||||||
    <link rel="stylesheet" href="user.css">
 | 
					 | 
				
			||||||
</head>
 | 
					 | 
				
			||||||
<body>
 | 
					 | 
				
			||||||
<noscript>You need to enable JavaScript to run this app.</noscript>
 | 
					 | 
				
			||||||
<section class="header">
 | 
					 | 
				
			||||||
    <h1>简陋信息页</h1>
 | 
					 | 
				
			||||||
</section>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<section class="header">
 | 
					 | 
				
			||||||
    <h3>上传材质</h3>
 | 
					 | 
				
			||||||
</section>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<form id="upload-form" action="#" enctype="multipart/form-data">
 | 
					 | 
				
			||||||
    <div class="mdc-form-field textureType">
 | 
					 | 
				
			||||||
        <label>材质类别: </label>
 | 
					 | 
				
			||||||
        <div id="radio-skin" class="mdc-radio">
 | 
					 | 
				
			||||||
            <input class="mdc-radio__native-control" type="radio" id="radio-3" name="type" value="skin" checked>
 | 
					 | 
				
			||||||
            <div class="mdc-radio__background">
 | 
					 | 
				
			||||||
                <div class="mdc-radio__outer-circle"></div>
 | 
					 | 
				
			||||||
                <div class="mdc-radio__inner-circle"></div>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
            <div class="mdc-radio__ripple"></div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <label for="radio-3">皮肤</label>
 | 
					 | 
				
			||||||
        <div id="radio-cape" class="mdc-radio">
 | 
					 | 
				
			||||||
            <input class="mdc-radio__native-control" type="radio" id="radio-4" name="type" value="cape">
 | 
					 | 
				
			||||||
            <div class="mdc-radio__background">
 | 
					 | 
				
			||||||
                <div class="mdc-radio__outer-circle"></div>
 | 
					 | 
				
			||||||
                <div class="mdc-radio__inner-circle"></div>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
            <div class="mdc-radio__ripple"></div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <label for="radio-3">披风</label>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
    <div class="mdc-form-field model">
 | 
					 | 
				
			||||||
        <label>材质模型: </label>
 | 
					 | 
				
			||||||
        <div id="radio-steve" class="mdc-radio">
 | 
					 | 
				
			||||||
            <input class="mdc-radio__native-control" type="radio" id="radio-1" name="model" value="default" checked>
 | 
					 | 
				
			||||||
            <div class="mdc-radio__background">
 | 
					 | 
				
			||||||
                <div class="mdc-radio__outer-circle"></div>
 | 
					 | 
				
			||||||
                <div class="mdc-radio__inner-circle"></div>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
            <div class="mdc-radio__ripple"></div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <label for="radio-1">Steve</label>
 | 
					 | 
				
			||||||
        <div id="radio-alex" class="mdc-radio">
 | 
					 | 
				
			||||||
            <input class="mdc-radio__native-control" type="radio" id="radio-2" name="model" value="slim">
 | 
					 | 
				
			||||||
            <div class="mdc-radio__background">
 | 
					 | 
				
			||||||
                <div class="mdc-radio__outer-circle"></div>
 | 
					 | 
				
			||||||
                <div class="mdc-radio__inner-circle"></div>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
            <div class="mdc-radio__ripple"></div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <label for="radio-2">Alex</label>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
    <div class="mdc-text-field url">
 | 
					 | 
				
			||||||
        <input type="url" class="mdc-text-field__input" id="url-input" name="url">
 | 
					 | 
				
			||||||
        <label class="mdc-floating-label" for="url-input">材质url</label>
 | 
					 | 
				
			||||||
        <div class="mdc-line-ripple"></div>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
    <label class="mdc-text-field mdc-text-field--outlined mdc-text-field--with-trailing-icon file">
 | 
					 | 
				
			||||||
        <input type="file" style="display: none;" accept="image/*" class="mdc-text-field__input" id="file-input"
 | 
					 | 
				
			||||||
               name="file" aria-label="Label">
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        <i class="material-icons mdc-text-field__icon mdc-text-field__icon--trailing" tabindex="0" role="button"
 | 
					 | 
				
			||||||
           onclick="$('#file-input').val('').change();">delete</i>
 | 
					 | 
				
			||||||
        <div class="mdc-notched-outline">
 | 
					 | 
				
			||||||
            <div class="mdc-notched-outline__leading"></div>
 | 
					 | 
				
			||||||
            <div class="mdc-notched-outline__notch">
 | 
					 | 
				
			||||||
                <label id="file-path" for="file-input" class="mdc-floating-label">或者选择一个图片</label>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
            <div class="mdc-notched-outline__trailing"></div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
    </label>
 | 
					 | 
				
			||||||
    <div class="button-container">
 | 
					 | 
				
			||||||
        <button type="submit" class="mdc-button mdc-button--raised upload">
 | 
					 | 
				
			||||||
            <div class="mdc-button__ripple"></div>
 | 
					 | 
				
			||||||
            <span class="mdc-button__label">
 | 
					 | 
				
			||||||
          上传
 | 
					 | 
				
			||||||
        </span>
 | 
					 | 
				
			||||||
        </button>
 | 
					 | 
				
			||||||
        <button type="button" id="delete-btn" class="mdc-button mdc-button--raised upload">
 | 
					 | 
				
			||||||
            <div class="mdc-button__ripple"></div>
 | 
					 | 
				
			||||||
            <span class="mdc-button__label">
 | 
					 | 
				
			||||||
          重置为默认
 | 
					 | 
				
			||||||
        </span>
 | 
					 | 
				
			||||||
        </button>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
</form>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<section class="header">
 | 
					 | 
				
			||||||
    <h3>更改游戏标签</h3>
 | 
					 | 
				
			||||||
</section>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<form id="change-form" action="#">
 | 
					 | 
				
			||||||
    <div class="mdc-text-field changeTo">
 | 
					 | 
				
			||||||
        <input type="text" class="mdc-text-field__input" id="changeTo-input" name="changeTo" required minlength="2"
 | 
					 | 
				
			||||||
               maxlength="16">
 | 
					 | 
				
			||||||
        <script>
 | 
					 | 
				
			||||||
            if (localStorage.profileName) document.getElementById("changeTo-input").value = localStorage.profileName;
 | 
					 | 
				
			||||||
        </script>
 | 
					 | 
				
			||||||
        <label class="mdc-floating-label" for="changeTo-input">游戏标签</label>
 | 
					 | 
				
			||||||
        <div class="mdc-line-ripple"></div>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
    <div class="button-container">
 | 
					 | 
				
			||||||
        <button type="submit" class="mdc-button mdc-button--raised submit">
 | 
					 | 
				
			||||||
            <div class="mdc-button__ripple"></div>
 | 
					 | 
				
			||||||
            <span class="mdc-button__label">
 | 
					 | 
				
			||||||
            更改
 | 
					 | 
				
			||||||
          </span>
 | 
					 | 
				
			||||||
        </button>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
</form>
 | 
					 | 
				
			||||||
<div class="mdc-snackbar">
 | 
					 | 
				
			||||||
    <div class="mdc-snackbar__surface">
 | 
					 | 
				
			||||||
        <div class="mdc-snackbar__label"
 | 
					 | 
				
			||||||
             role="status"
 | 
					 | 
				
			||||||
             aria-live="polite">
 | 
					 | 
				
			||||||
            上传失败
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<script src="https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js"></script>
 | 
					 | 
				
			||||||
<script src="user.js" async></script>
 | 
					 | 
				
			||||||
</body>
 | 
					 | 
				
			||||||
</html>
 | 
					 | 
				
			||||||
							
								
								
									
										242
									
								
								assets/user.js
									
									
									
									
									
								
							
							
						
						@@ -1,242 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2022. Gardel <sunxinao@hotmail.com> and contributors
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU Affero General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
					 | 
				
			||||||
 * (at your option) any later version.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU Affero General Public License for more details.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU Affero General Public License
 | 
					 | 
				
			||||||
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const MDCSnackbar = mdc.snackbar.MDCSnackbar;
 | 
					 | 
				
			||||||
const MDCTextField = mdc.textField.MDCTextField;
 | 
					 | 
				
			||||||
const MDCFormField = mdc.formField.MDCFormField;
 | 
					 | 
				
			||||||
const MDCRadio = mdc.radio.MDCRadio;
 | 
					 | 
				
			||||||
//const MDCRipple = mdc.ripple.MDCRipple;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const snackbar = new MDCSnackbar(document.querySelector('.mdc-snackbar'));
 | 
					 | 
				
			||||||
const modelField = new MDCFormField(document.querySelector('.model'));
 | 
					 | 
				
			||||||
const radio1 = new MDCRadio(document.querySelector('#radio-steve'));
 | 
					 | 
				
			||||||
const radio2 = new MDCRadio(document.querySelector('#radio-alex'));
 | 
					 | 
				
			||||||
const radio3 = new MDCRadio(document.querySelector('#radio-skin'));
 | 
					 | 
				
			||||||
const radio4 = new MDCRadio(document.querySelector('#radio-cape'));
 | 
					 | 
				
			||||||
modelField.input = {radio1, radio2};
 | 
					 | 
				
			||||||
const url = new MDCTextField(document.querySelector('.url'));
 | 
					 | 
				
			||||||
const file = new MDCTextField(document.querySelector('.file'));
 | 
					 | 
				
			||||||
const changeTo = new MDCTextField(document.querySelector('.changeTo'));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const modelTypeForm = document.querySelector('.mdc-form-field.model');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
snackbar.close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$("#file-input").change(function() {
 | 
					 | 
				
			||||||
    const path = this.value;
 | 
					 | 
				
			||||||
    if (!path) {
 | 
					 | 
				
			||||||
        $("#file-path").text("或选择一张图片");
 | 
					 | 
				
			||||||
        $(".url").show();
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        $("#file-path").text(path);
 | 
					 | 
				
			||||||
        url.value = '';
 | 
					 | 
				
			||||||
        $(".url").hide();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const modelTypeChange = function () {
 | 
					 | 
				
			||||||
    if (radio3.checked) {
 | 
					 | 
				
			||||||
        $(modelTypeForm).show();
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        $(modelTypeForm).hide();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
$("#radio-3").change(modelTypeChange)
 | 
					 | 
				
			||||||
$("#radio-4").change(modelTypeChange)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$("#url-input").on("input", function() {
 | 
					 | 
				
			||||||
    const url = this.value;
 | 
					 | 
				
			||||||
    if (!url) {
 | 
					 | 
				
			||||||
        $(".file").show();
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        file.value = '';
 | 
					 | 
				
			||||||
        $(".file").hide();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$(document).ready(function() {
 | 
					 | 
				
			||||||
    if (!localStorage.accessToken) {
 | 
					 | 
				
			||||||
        localStorage.loginTime = 1;
 | 
					 | 
				
			||||||
        window.location = "index.html";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    $.ajax({
 | 
					 | 
				
			||||||
        url: '/authserver/validate',
 | 
					 | 
				
			||||||
        type: 'POST',
 | 
					 | 
				
			||||||
        dataType: "JSON",
 | 
					 | 
				
			||||||
        contentType: "application/json",
 | 
					 | 
				
			||||||
        data: JSON.stringify({
 | 
					 | 
				
			||||||
            accessToken: localStorage.accessToken,
 | 
					 | 
				
			||||||
        }),
 | 
					 | 
				
			||||||
        success: function(data) {
 | 
					 | 
				
			||||||
            //有效,啥也不整
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        error: function(e) {
 | 
					 | 
				
			||||||
            if (e.status == 403) {
 | 
					 | 
				
			||||||
                // 持续套娃
 | 
					 | 
				
			||||||
                $.ajax({
 | 
					 | 
				
			||||||
                    url: '/authserver/refresh',
 | 
					 | 
				
			||||||
                    type: 'POST',
 | 
					 | 
				
			||||||
                    dataType: "JSON",
 | 
					 | 
				
			||||||
                    contentType: "application/json",
 | 
					 | 
				
			||||||
                    data: JSON.stringify({
 | 
					 | 
				
			||||||
                        accessToken: localStorage.accessToken,
 | 
					 | 
				
			||||||
                    }),
 | 
					 | 
				
			||||||
                    success: function(data) {
 | 
					 | 
				
			||||||
                        if (!data.accessToken) {
 | 
					 | 
				
			||||||
                            localStorage.loginTime = 1;
 | 
					 | 
				
			||||||
                            window.location = "index.html";
 | 
					 | 
				
			||||||
                        } else {
 | 
					 | 
				
			||||||
                            snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
                            snackbar.labelText = "刷新token成功,accessToken:" + data.accessToken;
 | 
					 | 
				
			||||||
                            snackbar.open();
 | 
					 | 
				
			||||||
                            localStorage.accessToken = data.accessToken;
 | 
					 | 
				
			||||||
                            localStorage.loginTime = new Date().getTime();
 | 
					 | 
				
			||||||
                            if(data.selectedProfile) {
 | 
					 | 
				
			||||||
                                localStorage.profileName = data.selectedProfile.name;
 | 
					 | 
				
			||||||
                                localStorage.uuid = data.selectedProfile.id;
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                    error: function(e) {
 | 
					 | 
				
			||||||
                        if (e.status == 403) {
 | 
					 | 
				
			||||||
                            localStorage.loginTime = 1;
 | 
					 | 
				
			||||||
                            window.location = "index.html";
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$("#upload-form").submit(function(e) {
 | 
					 | 
				
			||||||
    e.preventDefault();
 | 
					 | 
				
			||||||
    if (!url.value && !$("#file-input").val()) {
 | 
					 | 
				
			||||||
        snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
        snackbar.labelText = "没填信息";
 | 
					 | 
				
			||||||
        snackbar.open();
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    let textureType = 'skin'
 | 
					 | 
				
			||||||
    if (radio3.checked) {
 | 
					 | 
				
			||||||
        textureType = 'skin'
 | 
					 | 
				
			||||||
    } else if (radio4.checked) {
 | 
					 | 
				
			||||||
        textureType = 'cape'
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (!url.value) {
 | 
					 | 
				
			||||||
        const formData = new FormData();
 | 
					 | 
				
			||||||
        formData.append("model", radio1.checked ? radio1.value : radio2.value);
 | 
					 | 
				
			||||||
        formData.append("file", $("#file-input")[0].files[0]);
 | 
					 | 
				
			||||||
        //formData.contentType = "multipart/form-data";
 | 
					 | 
				
			||||||
        $.ajax({
 | 
					 | 
				
			||||||
            url: `/api/user/profile/${localStorage.uuid}/${textureType}`,
 | 
					 | 
				
			||||||
            type: 'PUT',
 | 
					 | 
				
			||||||
            processData: false,
 | 
					 | 
				
			||||||
            contentType: false,
 | 
					 | 
				
			||||||
            headers: {'Authorization':'Bearer ' + localStorage.accessToken},
 | 
					 | 
				
			||||||
            data: formData,
 | 
					 | 
				
			||||||
            success: function(data) {
 | 
					 | 
				
			||||||
                snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
                snackbar.labelText = "材质上传成功";
 | 
					 | 
				
			||||||
                snackbar.open();
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            error: function(e) {
 | 
					 | 
				
			||||||
                snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
                snackbar.labelText = "材质上传失败";
 | 
					 | 
				
			||||||
                snackbar.open();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    } else if (url.value) {
 | 
					 | 
				
			||||||
        $.ajax({
 | 
					 | 
				
			||||||
            url: `/api/user/profile/${localStorage.uuid}/${textureType}`,
 | 
					 | 
				
			||||||
            type: 'POST',
 | 
					 | 
				
			||||||
            dataType: "JSON",
 | 
					 | 
				
			||||||
            contentType: "application/json",
 | 
					 | 
				
			||||||
            headers: {'Authorization':'Bearer ' + localStorage.accessToken},
 | 
					 | 
				
			||||||
            data: JSON.stringify({
 | 
					 | 
				
			||||||
                model: radio1.checked ? radio1.value : radio2.value,
 | 
					 | 
				
			||||||
                url: url.value
 | 
					 | 
				
			||||||
            }),
 | 
					 | 
				
			||||||
            success: function(data) {
 | 
					 | 
				
			||||||
                snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
                snackbar.labelText = "材质上传成功";
 | 
					 | 
				
			||||||
                snackbar.open();
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            error: function(e) {
 | 
					 | 
				
			||||||
                snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
                snackbar.labelText = "材质上传失败";
 | 
					 | 
				
			||||||
                snackbar.open();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$("#change-form").submit(function(e) {
 | 
					 | 
				
			||||||
    e.preventDefault();
 | 
					 | 
				
			||||||
    if (changeTo.value.length <= 1) {
 | 
					 | 
				
			||||||
        snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
        snackbar.labelText = "更改失败, 角色名格式不正确";
 | 
					 | 
				
			||||||
        snackbar.open();
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    $.ajax({
 | 
					 | 
				
			||||||
        url: '/authserver/change',
 | 
					 | 
				
			||||||
        type: 'POST',
 | 
					 | 
				
			||||||
        dataType: "JSON",
 | 
					 | 
				
			||||||
        contentType: "application/json",
 | 
					 | 
				
			||||||
        data: JSON.stringify({
 | 
					 | 
				
			||||||
            accessToken: localStorage.accessToken,
 | 
					 | 
				
			||||||
            changeTo: changeTo.value
 | 
					 | 
				
			||||||
        }),
 | 
					 | 
				
			||||||
        success: function(data) {
 | 
					 | 
				
			||||||
            snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
            snackbar.labelText = "更改成功";
 | 
					 | 
				
			||||||
            snackbar.open();
 | 
					 | 
				
			||||||
            localStorage.profileName = changeTo.value;
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        error: function(e) {
 | 
					 | 
				
			||||||
            snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
            snackbar.labelText = "更改失败, 可能是角色名已存在";
 | 
					 | 
				
			||||||
            snackbar.open();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$('#delete-btn').click(function () {
 | 
					 | 
				
			||||||
    let textureType = 'skin'
 | 
					 | 
				
			||||||
    if (radio3.checked) {
 | 
					 | 
				
			||||||
        textureType = 'skin'
 | 
					 | 
				
			||||||
    } else if (radio4.checked) {
 | 
					 | 
				
			||||||
        textureType = 'cape'
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    $.ajax({
 | 
					 | 
				
			||||||
        url: `/api/user/profile/${localStorage.uuid}/${textureType}`,
 | 
					 | 
				
			||||||
        type: 'DELETE',
 | 
					 | 
				
			||||||
        headers: {'Authorization':'Bearer ' + localStorage.accessToken},
 | 
					 | 
				
			||||||
        success: function(data) {
 | 
					 | 
				
			||||||
            snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
            snackbar.labelText = "恢复成功";
 | 
					 | 
				
			||||||
            snackbar.open();
 | 
					 | 
				
			||||||
            localStorage.profileName = changeTo.value;
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        error: function(e) {
 | 
					 | 
				
			||||||
            snackbar.timeoutMs = 5000;
 | 
					 | 
				
			||||||
            snackbar.labelText = "重置失败";
 | 
					 | 
				
			||||||
            snackbar.open();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
})
 | 
					 | 
				
			||||||
@@ -6,7 +6,7 @@ server_name            = A Mojang Yggdrasil Server
 | 
				
			|||||||
implementation_name    = go-yggdrasil-server
 | 
					implementation_name    = go-yggdrasil-server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;版本
 | 
					;版本
 | 
				
			||||||
implementation_version = v0.1
 | 
					implementation_version = v0.0.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;皮肤、披风材质白名单
 | 
					;皮肤、披风材质白名单
 | 
				
			||||||
skin_domains           = .example.com, localhost
 | 
					skin_domains           = .example.com, localhost
 | 
				
			||||||
@@ -18,6 +18,9 @@ skin_root_url          = http://localhost:8080
 | 
				
			|||||||
;服务监听地址
 | 
					;服务监听地址
 | 
				
			||||||
server_address  = :8080
 | 
					server_address  = :8080
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;反向代理信任地址
 | 
				
			||||||
 | 
					trusted_proxies = 127.0.0.0/8, 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[database]
 | 
					[database]
 | 
				
			||||||
; Database driver type, mysql or sqlite
 | 
					; Database driver type, mysql or sqlite
 | 
				
			||||||
database_driver = sqlite
 | 
					database_driver = sqlite
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								frontend/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					# Logs
 | 
				
			||||||
 | 
					logs
 | 
				
			||||||
 | 
					*.log
 | 
				
			||||||
 | 
					npm-debug.log*
 | 
				
			||||||
 | 
					yarn-debug.log*
 | 
				
			||||||
 | 
					yarn-error.log*
 | 
				
			||||||
 | 
					pnpm-debug.log*
 | 
				
			||||||
 | 
					lerna-debug.log*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					node_modules
 | 
				
			||||||
 | 
					dist
 | 
				
			||||||
 | 
					dist-ssr
 | 
				
			||||||
 | 
					*.local
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Editor directories and files
 | 
				
			||||||
 | 
					.vscode/*
 | 
				
			||||||
 | 
					!.vscode/extensions.json
 | 
				
			||||||
 | 
					.idea
 | 
				
			||||||
 | 
					.DS_Store
 | 
				
			||||||
 | 
					*.suo
 | 
				
			||||||
 | 
					*.ntvs*
 | 
				
			||||||
 | 
					*.njsproj
 | 
				
			||||||
 | 
					*.sln
 | 
				
			||||||
 | 
					*.sw?
 | 
				
			||||||
							
								
								
									
										31
									
								
								frontend/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					<!--
 | 
				
			||||||
 | 
					  ~ Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					  ~
 | 
				
			||||||
 | 
					  ~ This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					  ~ it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					  ~ the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					  ~ (at your option) any later version.
 | 
				
			||||||
 | 
					  ~
 | 
				
			||||||
 | 
					  ~ This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					  ~ GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					  ~
 | 
				
			||||||
 | 
					  ~ You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					  ~ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					  -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html lang="en">
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					    <meta charset="UTF-8"/>
 | 
				
			||||||
 | 
					<!--    <link rel="icon" type="image/svg+xml" href="/vite.svg"/>-->
 | 
				
			||||||
 | 
					    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
 | 
				
			||||||
 | 
					    <title>Yggdrasil Go</title>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					<noscript>You need to enable JavaScript to run this app.</noscript>
 | 
				
			||||||
 | 
					<div id="root"></div>
 | 
				
			||||||
 | 
					<script type="module" src="src/main.tsx"></script>
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										38
									
								
								frontend/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "name": "yggdrasil-go",
 | 
				
			||||||
 | 
					  "private": true,
 | 
				
			||||||
 | 
					  "version": "0.0.1",
 | 
				
			||||||
 | 
					  "type": "module",
 | 
				
			||||||
 | 
					  "scripts": {
 | 
				
			||||||
 | 
					    "dev": "vite --host",
 | 
				
			||||||
 | 
					    "build": "tsc && vite build",
 | 
				
			||||||
 | 
					    "preview": "vite preview"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "dependencies": {
 | 
				
			||||||
 | 
					    "@emotion/react": "^11.10.5",
 | 
				
			||||||
 | 
					    "@emotion/styled": "^11.10.5",
 | 
				
			||||||
 | 
					    "@fontsource/roboto": "^4.5.8",
 | 
				
			||||||
 | 
					    "@mui/icons-material": "^5.11.0",
 | 
				
			||||||
 | 
					    "@mui/material": "^5.11.6",
 | 
				
			||||||
 | 
					    "@react-three/drei": "^9.56.12",
 | 
				
			||||||
 | 
					    "@react-three/fiber": "^8.10.1",
 | 
				
			||||||
 | 
					    "@react-three/postprocessing": "^2.7.0",
 | 
				
			||||||
 | 
					    "axios": "^1.2.6",
 | 
				
			||||||
 | 
					    "notistack": "^2.0.8",
 | 
				
			||||||
 | 
					    "postprocessing": "^6.29.3",
 | 
				
			||||||
 | 
					    "react": "^18.2.0",
 | 
				
			||||||
 | 
					    "react-dom": "^18.2.0",
 | 
				
			||||||
 | 
					    "react-hook-form": "^7.43.0",
 | 
				
			||||||
 | 
					    "three": "^0.148.0",
 | 
				
			||||||
 | 
					    "three-stdlib": "^2.21.8"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "devDependencies": {
 | 
				
			||||||
 | 
					    "@types/react": "^18.0.26",
 | 
				
			||||||
 | 
					    "@types/react-dom": "^18.0.9",
 | 
				
			||||||
 | 
					    "@types/three": "^0.148.0",
 | 
				
			||||||
 | 
					    "@vitejs/plugin-react": "^3.0.0",
 | 
				
			||||||
 | 
					    "typescript": "^4.9.3",
 | 
				
			||||||
 | 
					    "vite": "^4.0.0",
 | 
				
			||||||
 | 
					    "vite-plugin-mock-dev-server": "^0.3.16"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/slim/alex.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/slim/ari.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/slim/efe.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.3 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/slim/kai.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.5 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/slim/makena.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.4 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/slim/noor.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/slim/steve.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/slim/sunny.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/slim/zuri.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/wide/alex.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/wide/ari.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/wide/efe.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.3 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/wide/kai.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.5 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/wide/makena.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.4 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/wide/noor.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/wide/steve.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/wide/sunny.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								frontend/public/player/wide/zuri.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.1 KiB  | 
							
								
								
									
										23
									
								
								frontend/src/app.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#root {
 | 
				
			||||||
 | 
					  width: 100%;
 | 
				
			||||||
 | 
					  margin: 0 auto;
 | 
				
			||||||
 | 
					  padding: 2rem;
 | 
				
			||||||
 | 
					  text-align: center;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										105
									
								
								frontend/src/app.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,105 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import React from 'react';
 | 
				
			||||||
 | 
					import './app.css';
 | 
				
			||||||
 | 
					import Login from './login';
 | 
				
			||||||
 | 
					import {Container} from '@mui/material';
 | 
				
			||||||
 | 
					import {AppState} from './types';
 | 
				
			||||||
 | 
					import User from './user';
 | 
				
			||||||
 | 
					import axios from 'axios';
 | 
				
			||||||
 | 
					import {useSnackbar} from 'notistack';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function App() {
 | 
				
			||||||
 | 
					    const {enqueueSnackbar} = useSnackbar();
 | 
				
			||||||
 | 
					    const [appData, setAppData] = React.useState(() => {
 | 
				
			||||||
 | 
					        const saved = localStorage.getItem('appData');
 | 
				
			||||||
 | 
					        return (saved ? JSON.parse(saved) : {
 | 
				
			||||||
 | 
					            login: false,
 | 
				
			||||||
 | 
					            accessToken: '',
 | 
				
			||||||
 | 
					            tokenValid: false,
 | 
				
			||||||
 | 
					            loginTime: 0,
 | 
				
			||||||
 | 
					            profileName: '',
 | 
				
			||||||
 | 
					            uuid: ''
 | 
				
			||||||
 | 
					        }) as AppState;
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    React.useEffect(() => {
 | 
				
			||||||
 | 
					        localStorage.setItem('appData', JSON.stringify(appData));
 | 
				
			||||||
 | 
					    }, [appData]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const setTokenValid = (tokenValid: boolean) => appData.tokenValid != tokenValid && setAppData((oldData: AppState) => {
 | 
				
			||||||
 | 
					        return tokenValid ? {
 | 
				
			||||||
 | 
					            ...oldData,
 | 
				
			||||||
 | 
					            tokenValid: true
 | 
				
			||||||
 | 
					        } : {
 | 
				
			||||||
 | 
					            ...oldData,
 | 
				
			||||||
 | 
					            tokenValid: false,
 | 
				
			||||||
 | 
					            accessToken: '',
 | 
				
			||||||
 | 
					            loginTime: 0
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    setTokenValid((appData.accessToken && Date.now() - appData.loginTime < 30 * 86400 * 1000) as boolean)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (appData.tokenValid) {
 | 
				
			||||||
 | 
					        let postData = {
 | 
				
			||||||
 | 
					            accessToken: appData.accessToken,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        axios.post('/authserver/validate', postData)
 | 
				
			||||||
 | 
					            .catch(e => {
 | 
				
			||||||
 | 
					            const response = e.response;
 | 
				
			||||||
 | 
					            if (response && response.status == 403) {
 | 
				
			||||||
 | 
					                axios.post('/authserver/refresh', postData)
 | 
				
			||||||
 | 
					                    .then(response => {
 | 
				
			||||||
 | 
					                        const data = response.data;
 | 
				
			||||||
 | 
					                        if (data && data.accessToken) {
 | 
				
			||||||
 | 
					                            setAppData({
 | 
				
			||||||
 | 
					                                ...appData,
 | 
				
			||||||
 | 
					                                accessToken: data.accessToken,
 | 
				
			||||||
 | 
					                                loginTime: Date.now(),
 | 
				
			||||||
 | 
					                                profileName: data.selectedProfile?.name,
 | 
				
			||||||
 | 
					                                uuid: data.selectedProfile?.id
 | 
				
			||||||
 | 
					                            });
 | 
				
			||||||
 | 
					                            enqueueSnackbar('刷新token成功,accessToken:' + data.accessToken, {variant: 'success'});
 | 
				
			||||||
 | 
					                        } else {
 | 
				
			||||||
 | 
					                            setTokenValid(false);
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    })
 | 
				
			||||||
 | 
					                    .catch(e => {
 | 
				
			||||||
 | 
					                        const response = e.response;
 | 
				
			||||||
 | 
					                        if (response && response.status == 403) {
 | 
				
			||||||
 | 
					                            enqueueSnackbar('登录已过期', {variant: 'warning'});
 | 
				
			||||||
 | 
					                            setTokenValid(false);
 | 
				
			||||||
 | 
					                        } else {
 | 
				
			||||||
 | 
					                            enqueueSnackbar('网络错误:' + e.message, {variant: 'error'});
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                enqueueSnackbar('网络错误:' + e.message, {variant: 'error'});
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        <Container maxWidth={'lg'}>
 | 
				
			||||||
 | 
					            {appData.tokenValid ? <User appData={appData} setAppData={setAppData}/> : <Login appData={appData} setAppData={setAppData}/>}
 | 
				
			||||||
 | 
					        </Container>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default App;
 | 
				
			||||||
							
								
								
									
										24
									
								
								frontend/src/components.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import {Collapse, FormHelperText, FormHelperTextProps, useFormControl} from '@mui/material';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function FocusedShowHelperText(props: FormHelperTextProps) {
 | 
				
			||||||
 | 
					    const {focused} = useFormControl() || {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return <Collapse in={focused}><FormHelperText id={props.id}>{props.children}</FormHelperText></Collapse>;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										24
									
								
								frontend/src/index.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					body {
 | 
				
			||||||
 | 
					  margin: 0;
 | 
				
			||||||
 | 
					  display: flex;
 | 
				
			||||||
 | 
					  place-items: center;
 | 
				
			||||||
 | 
					  min-width: 320px;
 | 
				
			||||||
 | 
					  min-height: 100vh;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2022. Gardel <sunxinao@hotmail.com> and contributors
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 * it under the terms of the GNU Affero General Public License as published by
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
@@ -15,34 +15,30 @@
 | 
				
			|||||||
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
.header {
 | 
					.header {
 | 
				
			||||||
    text-align: center;
 | 
					    text-align: center;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.model,
 | 
					.login-card {
 | 
				
			||||||
.textureType,
 | 
					    padding: 14px 24px;
 | 
				
			||||||
.url,
 | 
					    margin: auto;
 | 
				
			||||||
.changeTo {
 | 
					 | 
				
			||||||
  display: block;
 | 
					 | 
				
			||||||
  width: 300px;
 | 
					 | 
				
			||||||
  margin: 20px auto;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.file {
 | 
					.username,
 | 
				
			||||||
    display: flex;
 | 
					.profileName,
 | 
				
			||||||
    width: 300px;
 | 
					.password {
 | 
				
			||||||
 | 
					    display: block;
 | 
				
			||||||
 | 
					    width: 87%;
 | 
				
			||||||
    margin: 20px auto;
 | 
					    margin: 20px auto;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.button-container {
 | 
					.button-container {
 | 
				
			||||||
    display: flex;
 | 
					    display: flex;
 | 
				
			||||||
    justify-content: flex-end;
 | 
					    justify-content: flex-end;
 | 
				
			||||||
  width: 300px;
 | 
					    width: 87%;
 | 
				
			||||||
    margin: auto;
 | 
					    margin: auto;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.button-container button {
 | 
					.button-container button {
 | 
				
			||||||
    margin: 3px;
 | 
					    margin: 3px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
							
								
								
									
										206
									
								
								frontend/src/login.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,206 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import React from 'react';
 | 
				
			||||||
 | 
					import Button from '@mui/material/Button';
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					    Box,
 | 
				
			||||||
 | 
					    Collapse,
 | 
				
			||||||
 | 
					    Container,
 | 
				
			||||||
 | 
					    FilledInput,
 | 
				
			||||||
 | 
					    FormControl,
 | 
				
			||||||
 | 
					    IconButton,
 | 
				
			||||||
 | 
					    InputAdornment,
 | 
				
			||||||
 | 
					    InputLabel,
 | 
				
			||||||
 | 
					    Paper,
 | 
				
			||||||
 | 
					    TextField
 | 
				
			||||||
 | 
					} from '@mui/material';
 | 
				
			||||||
 | 
					import {Visibility, VisibilityOff} from '@mui/icons-material';
 | 
				
			||||||
 | 
					import {AppState} from './types';
 | 
				
			||||||
 | 
					import './login.css';
 | 
				
			||||||
 | 
					import {SubmitHandler, useForm} from 'react-hook-form';
 | 
				
			||||||
 | 
					import axios from 'axios';
 | 
				
			||||||
 | 
					import {useSnackbar} from 'notistack';
 | 
				
			||||||
 | 
					import {FocusedShowHelperText} from './components';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Inputs = {
 | 
				
			||||||
 | 
					    username: string,
 | 
				
			||||||
 | 
					    profileName: string,
 | 
				
			||||||
 | 
					    password: string
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function Login(props: { appData: AppState, setAppData: React.Dispatch<React.SetStateAction<AppState>> }) {
 | 
				
			||||||
 | 
					    const {appData, setAppData} = props;
 | 
				
			||||||
 | 
					    const {enqueueSnackbar} = useSnackbar();
 | 
				
			||||||
 | 
					    const {register, handleSubmit, formState: {errors}} = useForm<Inputs>();
 | 
				
			||||||
 | 
					    const [submitting, setSubmitting] = React.useState(false);
 | 
				
			||||||
 | 
					    const onSubmit: SubmitHandler<Inputs> = data => {
 | 
				
			||||||
 | 
					        setSubmitting(true)
 | 
				
			||||||
 | 
					        if (appData.login) {
 | 
				
			||||||
 | 
					            axios.post('/authserver/authenticate', {
 | 
				
			||||||
 | 
					                username: data.username,
 | 
				
			||||||
 | 
					                password: data.password
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					                .then(response => {
 | 
				
			||||||
 | 
					                    let data = response.data
 | 
				
			||||||
 | 
					                    if (data && data.accessToken) {
 | 
				
			||||||
 | 
					                        enqueueSnackbar("登录成功,accessToken:" + data.accessToken, {variant: 'success'});
 | 
				
			||||||
 | 
					                        setAppData({
 | 
				
			||||||
 | 
					                            ...appData,
 | 
				
			||||||
 | 
					                            accessToken: data.accessToken,
 | 
				
			||||||
 | 
					                            tokenValid: true,
 | 
				
			||||||
 | 
					                            loginTime: Date.now(),
 | 
				
			||||||
 | 
					                            profileName: data.selectedProfile?.name,
 | 
				
			||||||
 | 
					                            uuid: data.selectedProfile?.id
 | 
				
			||||||
 | 
					                        });
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        enqueueSnackbar(data && data.errorMessage ? "登录失败: " + data.errorMessage: "登陆失败", {variant: 'error'});
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					                .catch(e => {
 | 
				
			||||||
 | 
					                    const response = e.response;
 | 
				
			||||||
 | 
					                    if (response && response.status == 403) {
 | 
				
			||||||
 | 
					                        enqueueSnackbar('登录失败: ' + response.data.errorMessage, {variant: 'error'});
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        enqueueSnackbar('网络错误:' + e.message, {variant: 'error'});
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					                .finally(() => setSubmitting(false))
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            axios.post('/authserver/register', {
 | 
				
			||||||
 | 
					                username: data.username,
 | 
				
			||||||
 | 
					                password: data.password,
 | 
				
			||||||
 | 
					                profileName: data.profileName
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					                .then(response => {
 | 
				
			||||||
 | 
					                    let data = response.data
 | 
				
			||||||
 | 
					                    if (data && data.id) {
 | 
				
			||||||
 | 
					                        enqueueSnackbar("注册成功,uuid:" + data.id, {variant: 'success'});
 | 
				
			||||||
 | 
					                        setLogin(true)
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        enqueueSnackbar(data && data.errorMessage ? "注册失败: " + data.errorMessage: "注册失败", {variant: 'error'});
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					                .catch(e => {
 | 
				
			||||||
 | 
					                    const response = e.response;
 | 
				
			||||||
 | 
					                    if (response && response.data) {
 | 
				
			||||||
 | 
					                        let errorMessage = response.data.errorMessage;
 | 
				
			||||||
 | 
					                        let message =  "注册失败: " + errorMessage;
 | 
				
			||||||
 | 
					                        if (errorMessage === "profileName exist") {
 | 
				
			||||||
 | 
					                            message = "注册失败: 角色名已存在";
 | 
				
			||||||
 | 
					                        } else if (errorMessage === "profileName duplicate") {
 | 
				
			||||||
 | 
					                            message = "注册失败: 角色名与正版用户冲突";
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        enqueueSnackbar(message, {variant: 'error'});
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        enqueueSnackbar('网络错误:' + e.message, {variant: 'error'});
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					                .finally(() => setSubmitting(false))
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const [showPassword, setShowPassword] = React.useState(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const handleClickShowPassword = () => setShowPassword((show) => !show);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => {
 | 
				
			||||||
 | 
					        event.preventDefault();
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const setLogin = (login: boolean) => setAppData((oldData: AppState) => {
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...oldData,
 | 
				
			||||||
 | 
					            login
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        <Container maxWidth={'sm'}>
 | 
				
			||||||
 | 
					            <Paper className={'login-card'}>
 | 
				
			||||||
 | 
					                <section className="header">
 | 
				
			||||||
 | 
					                    <h1>简陋注册页</h1>
 | 
				
			||||||
 | 
					                </section>
 | 
				
			||||||
 | 
					                <Box component="form" autoComplete="off" onSubmit={handleSubmit(onSubmit)}>
 | 
				
			||||||
 | 
					                    <div className='username'>
 | 
				
			||||||
 | 
					                        <TextField
 | 
				
			||||||
 | 
					                            id="username-input"
 | 
				
			||||||
 | 
					                            name='username'
 | 
				
			||||||
 | 
					                            fullWidth
 | 
				
			||||||
 | 
					                            label="邮箱"
 | 
				
			||||||
 | 
					                            variant="filled"
 | 
				
			||||||
 | 
					                            required
 | 
				
			||||||
 | 
					                            error={errors.username && true}
 | 
				
			||||||
 | 
					                            type='email'
 | 
				
			||||||
 | 
					                            inputProps={{
 | 
				
			||||||
 | 
					                                ...register('username', {required: true})
 | 
				
			||||||
 | 
					                            }}
 | 
				
			||||||
 | 
					                        />
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                    <Collapse in={!appData.login} className='profileName'>
 | 
				
			||||||
 | 
					                        <FormControl fullWidth variant="filled" required={!appData.login} error={errors.profileName && true}>
 | 
				
			||||||
 | 
					                            <InputLabel htmlFor="profileName-input">角色名</InputLabel>
 | 
				
			||||||
 | 
					                            <FilledInput
 | 
				
			||||||
 | 
					                                id="profileName-input"
 | 
				
			||||||
 | 
					                                name="profileName"
 | 
				
			||||||
 | 
					                                required={!appData.login}
 | 
				
			||||||
 | 
					                                inputProps={appData.login ? {} : {
 | 
				
			||||||
 | 
					                                    minLength: '2', maxLength: 16,
 | 
				
			||||||
 | 
					                                    ...register('profileName', {required: true, minLength: 2, pattern: /^[a-zA-Z0-9_]{1,16}$/, maxLength: 16})
 | 
				
			||||||
 | 
					                                }}
 | 
				
			||||||
 | 
					                            />
 | 
				
			||||||
 | 
					                            <FocusedShowHelperText id="profileName-input-helper-text">字母,数字或下划线</FocusedShowHelperText>
 | 
				
			||||||
 | 
					                        </FormControl>
 | 
				
			||||||
 | 
					                    </Collapse>
 | 
				
			||||||
 | 
					                    <div className='password'>
 | 
				
			||||||
 | 
					                        <FormControl fullWidth variant="filled" required error={errors.password && true}>
 | 
				
			||||||
 | 
					                            <InputLabel htmlFor="password-input">密码</InputLabel>
 | 
				
			||||||
 | 
					                            <FilledInput
 | 
				
			||||||
 | 
					                                id="password-input"
 | 
				
			||||||
 | 
					                                name="password"
 | 
				
			||||||
 | 
					                                required
 | 
				
			||||||
 | 
					                                type={showPassword ? 'text' : 'password'}
 | 
				
			||||||
 | 
					                                endAdornment={
 | 
				
			||||||
 | 
					                                    <InputAdornment position="end">
 | 
				
			||||||
 | 
					                                        <IconButton
 | 
				
			||||||
 | 
					                                            aria-label="显示密码"
 | 
				
			||||||
 | 
					                                            onClick={handleClickShowPassword}
 | 
				
			||||||
 | 
					                                            onMouseDown={handleMouseDownPassword}
 | 
				
			||||||
 | 
					                                            edge="end">
 | 
				
			||||||
 | 
					                                            {showPassword ? <VisibilityOff/> : <Visibility/>}
 | 
				
			||||||
 | 
					                                        </IconButton>
 | 
				
			||||||
 | 
					                                    </InputAdornment>
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
 | 
					                                inputProps={{
 | 
				
			||||||
 | 
					                                    minLength: '6',
 | 
				
			||||||
 | 
					                                    ...register('password', {required: true, minLength: 6})
 | 
				
			||||||
 | 
					                                }}
 | 
				
			||||||
 | 
					                            />
 | 
				
			||||||
 | 
					                            <FocusedShowHelperText id="password-input-helper-text">警告: 暂无重置密码接口,请妥善保管密码</FocusedShowHelperText>
 | 
				
			||||||
 | 
					                        </FormControl>
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                    <div className='button-container'>
 | 
				
			||||||
 | 
					                        <Button variant='contained' onClick={() => setLogin(!appData.login)} disabled={submitting}>{appData.login ? '注册' : '已有帐号登录'}</Button>
 | 
				
			||||||
 | 
					                        <Button variant='contained' type='submit' disabled={submitting}>{appData.login ? '登录' : '注册'}</Button>
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                </Box>
 | 
				
			||||||
 | 
					            </Paper>
 | 
				
			||||||
 | 
					        </Container>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default Login;
 | 
				
			||||||
							
								
								
									
										36
									
								
								frontend/src/main.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import React from 'react';
 | 
				
			||||||
 | 
					import ReactDOM from 'react-dom/client';
 | 
				
			||||||
 | 
					import './index.css';
 | 
				
			||||||
 | 
					import '@fontsource/roboto/300.css';
 | 
				
			||||||
 | 
					import '@fontsource/roboto/400.css';
 | 
				
			||||||
 | 
					import '@fontsource/roboto/500.css';
 | 
				
			||||||
 | 
					import '@fontsource/roboto/700.css';
 | 
				
			||||||
 | 
					import { SnackbarProvider } from 'notistack';
 | 
				
			||||||
 | 
					import {CssBaseline} from '@mui/material';
 | 
				
			||||||
 | 
					import App from './app';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
 | 
				
			||||||
 | 
					    <React.StrictMode>
 | 
				
			||||||
 | 
					        <CssBaseline/>
 | 
				
			||||||
 | 
					        <SnackbarProvider maxSnack={3} anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}>
 | 
				
			||||||
 | 
					            <App/>
 | 
				
			||||||
 | 
					        </SnackbarProvider>
 | 
				
			||||||
 | 
					    </React.StrictMode>,
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
							
								
								
									
										96
									
								
								frontend/src/skinrender/skin-render.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,96 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import {Box} from '@mui/material';
 | 
				
			||||||
 | 
					import * as THREE from 'three';
 | 
				
			||||||
 | 
					import {Canvas, RootState, useFrame, useLoader} from '@react-three/fiber';
 | 
				
			||||||
 | 
					import React from 'react';
 | 
				
			||||||
 | 
					import createPlayerModel from './utils';
 | 
				
			||||||
 | 
					import {OrbitControls} from '@react-three/drei';
 | 
				
			||||||
 | 
					import {EffectComposer, Vignette, SMAA, SSAO, SSR} from '@react-three/postprocessing';
 | 
				
			||||||
 | 
					import {BlendFunction} from 'postprocessing';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function PlayerModel(props: { skinUrl: string, capeUrl?: string, slim?: boolean }) {
 | 
				
			||||||
 | 
					    const {skinUrl, capeUrl, slim} = props;
 | 
				
			||||||
 | 
					    console.log(props);
 | 
				
			||||||
 | 
					    const skinTexture: THREE.Texture = useLoader(THREE.TextureLoader, skinUrl);
 | 
				
			||||||
 | 
					    skinTexture.magFilter = THREE.NearestFilter;
 | 
				
			||||||
 | 
					    skinTexture.minFilter = THREE.NearestFilter;
 | 
				
			||||||
 | 
					    skinTexture.anisotropy = 0;
 | 
				
			||||||
 | 
					    skinTexture.needsUpdate = true;
 | 
				
			||||||
 | 
					    let version = 0;
 | 
				
			||||||
 | 
					    if (skinTexture.image.height > 32) {
 | 
				
			||||||
 | 
					        version = 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let capeTexture: THREE.Texture | undefined = undefined;
 | 
				
			||||||
 | 
					    if (capeUrl) {
 | 
				
			||||||
 | 
					        capeTexture = useLoader(THREE.TextureLoader, capeUrl);
 | 
				
			||||||
 | 
					        if (capeTexture) {
 | 
				
			||||||
 | 
					            capeTexture.magFilter = THREE.NearestFilter;
 | 
				
			||||||
 | 
					            capeTexture.minFilter = THREE.NearestFilter;
 | 
				
			||||||
 | 
					            capeTexture.anisotropy = 0;
 | 
				
			||||||
 | 
					            capeTexture.needsUpdate = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let playerModel = createPlayerModel(skinTexture, capeTexture, version, slim);
 | 
				
			||||||
 | 
					    useFrame((state, delta) => {
 | 
				
			||||||
 | 
					        playerModel.rotation.y += delta * 0.7;
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        <primitive object={playerModel} position={[0, -10, 0]}/>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function SkinRender(props: { skinUrl: string, capeUrl?: string, slim?: boolean }) {
 | 
				
			||||||
 | 
					    const onCanvasCreate = (state: RootState) => {
 | 
				
			||||||
 | 
					        state.gl.shadowMap.enabled = true;
 | 
				
			||||||
 | 
					        state.gl.shadowMap.type = THREE.PCFSoftShadowMap;
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        <Box component="div" height="600px">
 | 
				
			||||||
 | 
					            <section className="header">
 | 
				
			||||||
 | 
					                <h3>预览</h3>
 | 
				
			||||||
 | 
					            </section>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <Canvas
 | 
				
			||||||
 | 
					                camera={{position: [0, 15, 35], near: 5}}
 | 
				
			||||||
 | 
					                gl={{antialias: true, alpha: true, preserveDrawingBuffer: true}}
 | 
				
			||||||
 | 
					                onCreated={onCanvasCreate}>
 | 
				
			||||||
 | 
					                <ambientLight color={0xa0a0a0}/>
 | 
				
			||||||
 | 
					                <PlayerModel {...props}/>
 | 
				
			||||||
 | 
					                <OrbitControls makeDefault/>
 | 
				
			||||||
 | 
					                <EffectComposer>
 | 
				
			||||||
 | 
					                    <SSAO
 | 
				
			||||||
 | 
					                        blendFunction={BlendFunction.OVERLAY}
 | 
				
			||||||
 | 
					                        samples={30}
 | 
				
			||||||
 | 
					                        rings={4}
 | 
				
			||||||
 | 
					                        distanceThreshold={1.0}
 | 
				
			||||||
 | 
					                        distanceFalloff={0.0}
 | 
				
			||||||
 | 
					                        rangeThreshold={0.5}
 | 
				
			||||||
 | 
					                        rangeFalloff={0.1}
 | 
				
			||||||
 | 
					                        luminanceInfluence={0.9}
 | 
				
			||||||
 | 
					                        radius={20}
 | 
				
			||||||
 | 
					                        scale={0.5}
 | 
				
			||||||
 | 
					                        bias={0.5}
 | 
				
			||||||
 | 
					                    />
 | 
				
			||||||
 | 
					                </EffectComposer>
 | 
				
			||||||
 | 
					            </Canvas>
 | 
				
			||||||
 | 
					        </Box>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default SkinRender;
 | 
				
			||||||
							
								
								
									
										1105
									
								
								frontend/src/skinrender/texture-positions.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										314
									
								
								frontend/src/skinrender/utils.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,314 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import * as THREE from 'three';
 | 
				
			||||||
 | 
					import {texturePositions} from './texture-positions';
 | 
				
			||||||
 | 
					import {BufferAttribute} from 'three';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function createCube(texture: THREE.Texture, width: number, height: number, depth: number, textures: any, slim: boolean, name: string, transparent: boolean = false) {
 | 
				
			||||||
 | 
					    let textureWidth: number = texture.image.width;
 | 
				
			||||||
 | 
					    let textureHeight: number = texture.image.height;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let geometry = new THREE.BoxGeometry(width, height, depth);
 | 
				
			||||||
 | 
					    let material = new THREE.MeshStandardMaterial({
 | 
				
			||||||
 | 
					        /*color: 0x00ff00,*/
 | 
				
			||||||
 | 
					        map: texture,
 | 
				
			||||||
 | 
					        transparent: transparent || false,
 | 
				
			||||||
 | 
					        alphaTest: 0.1,
 | 
				
			||||||
 | 
					        side: transparent ? THREE.DoubleSide : THREE.FrontSide
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    geometry.computeBoundingBox();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const uvAttribute = geometry.getAttribute('uv') as BufferAttribute;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let faceNames = ['right', 'left', 'top', 'bottom', 'front', 'back'];
 | 
				
			||||||
 | 
					    let faceUvs = [];
 | 
				
			||||||
 | 
					    for (let i = 0; i < faceNames.length; i++) {
 | 
				
			||||||
 | 
					        let face = textures[faceNames[i]];
 | 
				
			||||||
 | 
					        // if (faceNames[i] === 'back') {
 | 
				
			||||||
 | 
					            //     console.log(face)
 | 
				
			||||||
 | 
					            // console.log("X: " + (slim && face.sx ? face.sx : face.x))
 | 
				
			||||||
 | 
					            // console.log("W: " + (slim && face.sw ? face.sw : face.w))
 | 
				
			||||||
 | 
					        // }
 | 
				
			||||||
 | 
					        let w = textureWidth;
 | 
				
			||||||
 | 
					        let h = textureHeight;
 | 
				
			||||||
 | 
					        let tx1 = ((slim && face.sx ? face.sx : face.x) / w);
 | 
				
			||||||
 | 
					        let ty1 = (face.y / h);
 | 
				
			||||||
 | 
					        let tx2 = (((slim && face.sx ? face.sx : face.x) + (slim && face.sw ? face.sw : face.w)) / w);
 | 
				
			||||||
 | 
					        let ty2 = ((face.y + face.h) / h);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        faceUvs[i] = [
 | 
				
			||||||
 | 
					            new THREE.Vector2(tx1, ty2),
 | 
				
			||||||
 | 
					            new THREE.Vector2(tx1, ty1),
 | 
				
			||||||
 | 
					            new THREE.Vector2(tx2, ty1),
 | 
				
			||||||
 | 
					            new THREE.Vector2(tx2, ty2)
 | 
				
			||||||
 | 
					        ];
 | 
				
			||||||
 | 
					        // console.log(faceUvs[i])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let flipX = face.flipX;
 | 
				
			||||||
 | 
					        let flipY = face.flipY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let temp;
 | 
				
			||||||
 | 
					        if (flipY) {
 | 
				
			||||||
 | 
					            temp = faceUvs[i].slice(0);
 | 
				
			||||||
 | 
					            faceUvs[i][0] = temp[2];
 | 
				
			||||||
 | 
					            faceUvs[i][1] = temp[3];
 | 
				
			||||||
 | 
					            faceUvs[i][2] = temp[0];
 | 
				
			||||||
 | 
					            faceUvs[i][3] = temp[1];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (flipX) {//flip x
 | 
				
			||||||
 | 
					            temp = faceUvs[i].slice(0);
 | 
				
			||||||
 | 
					            faceUvs[i][0] = temp[3];
 | 
				
			||||||
 | 
					            faceUvs[i][1] = temp[2];
 | 
				
			||||||
 | 
					            faceUvs[i][2] = temp[1];
 | 
				
			||||||
 | 
					            faceUvs[i][3] = temp[0];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let j = 0;
 | 
				
			||||||
 | 
					    for (let i = 0; i < faceUvs.length; i++) {
 | 
				
			||||||
 | 
					        uvAttribute.setXY(j++, faceUvs[i][0].x, faceUvs[i][0].y);
 | 
				
			||||||
 | 
					        uvAttribute.setXY(j++, faceUvs[i][3].x, faceUvs[i][3].y);
 | 
				
			||||||
 | 
					        uvAttribute.setXY(j++, faceUvs[i][1].x, faceUvs[i][1].y);
 | 
				
			||||||
 | 
					        uvAttribute.setXY(j++, faceUvs[i][2].x, faceUvs[i][2].y);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    uvAttribute.needsUpdate = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let cube = new THREE.Mesh(geometry, material);
 | 
				
			||||||
 | 
					    cube.name = name;
 | 
				
			||||||
 | 
					    // cube.position.set(x, y, z);
 | 
				
			||||||
 | 
					    cube.castShadow = true;
 | 
				
			||||||
 | 
					    cube.receiveShadow = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return cube;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default function createPlayerModel(skinTexture: THREE.Texture, capeTexture: THREE.Texture | null | undefined, v: number, slim: boolean = false, capeType?: string): THREE.Object3D<THREE.Event> {
 | 
				
			||||||
 | 
					    let headGroup = new THREE.Object3D();
 | 
				
			||||||
 | 
					    headGroup.name = 'headGroup';
 | 
				
			||||||
 | 
					    headGroup.position.x = 0;
 | 
				
			||||||
 | 
					    headGroup.position.y = 28;
 | 
				
			||||||
 | 
					    headGroup.position.z = 0;
 | 
				
			||||||
 | 
					    headGroup.translateOnAxis(new THREE.Vector3(0, 1, 0), -4);
 | 
				
			||||||
 | 
					    let head = createCube(skinTexture,
 | 
				
			||||||
 | 
					        8, 8, 8,
 | 
				
			||||||
 | 
					        texturePositions.head[v],
 | 
				
			||||||
 | 
					        slim,
 | 
				
			||||||
 | 
					        'head'
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    head.translateOnAxis(new THREE.Vector3(0, 1, 0), 4);
 | 
				
			||||||
 | 
					    headGroup.add(head);
 | 
				
			||||||
 | 
					    let hat = createCube(skinTexture,
 | 
				
			||||||
 | 
					        8.667, 8.667, 8.667,
 | 
				
			||||||
 | 
					        texturePositions.hat[v],
 | 
				
			||||||
 | 
					        slim,
 | 
				
			||||||
 | 
					        'hat',
 | 
				
			||||||
 | 
					        true
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    hat.translateOnAxis(new THREE.Vector3(0, 1, 0), 4);
 | 
				
			||||||
 | 
					    headGroup.add(hat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let bodyGroup = new THREE.Object3D();
 | 
				
			||||||
 | 
					    bodyGroup.name = 'bodyGroup';
 | 
				
			||||||
 | 
					    bodyGroup.position.x = 0;
 | 
				
			||||||
 | 
					    bodyGroup.position.y = 18;
 | 
				
			||||||
 | 
					    bodyGroup.position.z = 0;
 | 
				
			||||||
 | 
					    let body = createCube(skinTexture,
 | 
				
			||||||
 | 
					        8, 12, 4,
 | 
				
			||||||
 | 
					        texturePositions.body[v],
 | 
				
			||||||
 | 
					        slim,
 | 
				
			||||||
 | 
					        'body'
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    bodyGroup.add(body);
 | 
				
			||||||
 | 
					    if (v >= 1) {
 | 
				
			||||||
 | 
					        let jacket = createCube(skinTexture,
 | 
				
			||||||
 | 
					            8.667, 12.667, 4.667,
 | 
				
			||||||
 | 
					            texturePositions.jacket,
 | 
				
			||||||
 | 
					            slim,
 | 
				
			||||||
 | 
					            'jacket',
 | 
				
			||||||
 | 
					            true
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        bodyGroup.add(jacket);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let leftArmGroup = new THREE.Object3D();
 | 
				
			||||||
 | 
					    leftArmGroup.name = 'leftArmGroup';
 | 
				
			||||||
 | 
					    leftArmGroup.position.x = slim ? -5.5 : -6;
 | 
				
			||||||
 | 
					    leftArmGroup.position.y = 18;
 | 
				
			||||||
 | 
					    leftArmGroup.position.z = 0;
 | 
				
			||||||
 | 
					    leftArmGroup.translateOnAxis(new THREE.Vector3(0, 1, 0), 4);
 | 
				
			||||||
 | 
					    let leftArm = createCube(skinTexture,
 | 
				
			||||||
 | 
					        slim ? 3 : 4, 12, 4,
 | 
				
			||||||
 | 
					        texturePositions.leftArm[v],
 | 
				
			||||||
 | 
					        slim,
 | 
				
			||||||
 | 
					        'leftArm'
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    leftArm.translateOnAxis(new THREE.Vector3(0, 1, 0), -4);
 | 
				
			||||||
 | 
					    leftArmGroup.add(leftArm);
 | 
				
			||||||
 | 
					    if (v >= 1) {
 | 
				
			||||||
 | 
					        let leftSleeve = createCube(skinTexture,
 | 
				
			||||||
 | 
					            slim ? 3.667 : 4.667, 12.667, 4.667,
 | 
				
			||||||
 | 
					            texturePositions.leftSleeve,
 | 
				
			||||||
 | 
					            slim,
 | 
				
			||||||
 | 
					            'leftSleeve',
 | 
				
			||||||
 | 
					            true
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        leftSleeve.translateOnAxis(new THREE.Vector3(0, 1, 0), -4);
 | 
				
			||||||
 | 
					        leftArmGroup.add(leftSleeve);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let rightArmGroup = new THREE.Object3D();
 | 
				
			||||||
 | 
					    rightArmGroup.name = 'rightArmGroup';
 | 
				
			||||||
 | 
					    rightArmGroup.position.x = slim ? 5.5 : 6;
 | 
				
			||||||
 | 
					    rightArmGroup.position.y = 18;
 | 
				
			||||||
 | 
					    rightArmGroup.position.z = 0;
 | 
				
			||||||
 | 
					    rightArmGroup.translateOnAxis(new THREE.Vector3(0, 1, 0), 4);
 | 
				
			||||||
 | 
					    let rightArm = createCube(skinTexture,
 | 
				
			||||||
 | 
					        slim ? 3 : 4, 12, 4,
 | 
				
			||||||
 | 
					        texturePositions.rightArm[v],
 | 
				
			||||||
 | 
					        slim,
 | 
				
			||||||
 | 
					        'rightArm'
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    rightArm.translateOnAxis(new THREE.Vector3(0, 1, 0), -4);
 | 
				
			||||||
 | 
					    rightArmGroup.add(rightArm);
 | 
				
			||||||
 | 
					    if (v >= 1) {
 | 
				
			||||||
 | 
					        let rightSleeve = createCube(skinTexture,
 | 
				
			||||||
 | 
					            slim ? 3.667 : 4.667, 12.667, 4.667,
 | 
				
			||||||
 | 
					            texturePositions.rightSleeve,
 | 
				
			||||||
 | 
					            slim,
 | 
				
			||||||
 | 
					            'rightSleeve',
 | 
				
			||||||
 | 
					            true
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        rightSleeve.translateOnAxis(new THREE.Vector3(0, 1, 0), -4);
 | 
				
			||||||
 | 
					        rightArmGroup.add(rightSleeve);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let leftLegGroup = new THREE.Object3D();
 | 
				
			||||||
 | 
					    leftLegGroup.name = 'leftLegGroup';
 | 
				
			||||||
 | 
					    leftLegGroup.position.x = -2;
 | 
				
			||||||
 | 
					    leftLegGroup.position.y = 6;
 | 
				
			||||||
 | 
					    leftLegGroup.position.z = 0;
 | 
				
			||||||
 | 
					    leftLegGroup.translateOnAxis(new THREE.Vector3(0, 1, 0), 4);
 | 
				
			||||||
 | 
					    let leftLeg = createCube(skinTexture,
 | 
				
			||||||
 | 
					        4, 12, 4,
 | 
				
			||||||
 | 
					        texturePositions.leftLeg[v],
 | 
				
			||||||
 | 
					        slim,
 | 
				
			||||||
 | 
					        'leftLeg'
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    leftLeg.translateOnAxis(new THREE.Vector3(0, 1, 0), -4);
 | 
				
			||||||
 | 
					    leftLegGroup.add(leftLeg);
 | 
				
			||||||
 | 
					    if (v >= 1) {
 | 
				
			||||||
 | 
					        let leftTrousers = createCube(skinTexture,
 | 
				
			||||||
 | 
					            4.667, 12.667, 4.667,
 | 
				
			||||||
 | 
					            texturePositions.leftTrousers,
 | 
				
			||||||
 | 
					            slim,
 | 
				
			||||||
 | 
					            'leftTrousers',
 | 
				
			||||||
 | 
					            true
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        leftTrousers.translateOnAxis(new THREE.Vector3(0, 1, 0), -4);
 | 
				
			||||||
 | 
					        leftLegGroup.add(leftTrousers);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let rightLegGroup = new THREE.Object3D();
 | 
				
			||||||
 | 
					    rightLegGroup.name = 'rightLegGroup';
 | 
				
			||||||
 | 
					    rightLegGroup.position.x = 2;
 | 
				
			||||||
 | 
					    rightLegGroup.position.y = 6;
 | 
				
			||||||
 | 
					    rightLegGroup.position.z = 0;
 | 
				
			||||||
 | 
					    rightLegGroup.translateOnAxis(new THREE.Vector3(0, 1, 0), 4);
 | 
				
			||||||
 | 
					    let rightLeg = createCube(skinTexture,
 | 
				
			||||||
 | 
					        4, 12, 4,
 | 
				
			||||||
 | 
					        texturePositions.rightLeg[v],
 | 
				
			||||||
 | 
					        slim,
 | 
				
			||||||
 | 
					        'rightLeg'
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    rightLeg.translateOnAxis(new THREE.Vector3(0, 1, 0), -4);
 | 
				
			||||||
 | 
					    rightLegGroup.add(rightLeg);
 | 
				
			||||||
 | 
					    if (v >= 1) {
 | 
				
			||||||
 | 
					        let rightTrousers = createCube(skinTexture,
 | 
				
			||||||
 | 
					            4.667, 12.667, 4.667,
 | 
				
			||||||
 | 
					            texturePositions.rightTrousers,
 | 
				
			||||||
 | 
					            slim,
 | 
				
			||||||
 | 
					            'rightTrousers',
 | 
				
			||||||
 | 
					            true
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        rightTrousers.translateOnAxis(new THREE.Vector3(0, 1, 0), -4);
 | 
				
			||||||
 | 
					        rightLegGroup.add(rightTrousers);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let playerGroup = new THREE.Object3D();
 | 
				
			||||||
 | 
					    playerGroup.add(headGroup);
 | 
				
			||||||
 | 
					    playerGroup.add(bodyGroup);
 | 
				
			||||||
 | 
					    playerGroup.add(leftArmGroup);
 | 
				
			||||||
 | 
					    playerGroup.add(rightArmGroup);
 | 
				
			||||||
 | 
					    playerGroup.add(leftLegGroup);
 | 
				
			||||||
 | 
					    playerGroup.add(rightLegGroup);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (capeTexture) {
 | 
				
			||||||
 | 
					        console.log(texturePositions);
 | 
				
			||||||
 | 
					        let capeTextureCoordinates = texturePositions.capeRelative;
 | 
				
			||||||
 | 
					        if (capeType === 'optifine') {
 | 
				
			||||||
 | 
					            capeTextureCoordinates = texturePositions.capeOptifineRelative;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (capeType === 'labymod') {
 | 
				
			||||||
 | 
					            capeTextureCoordinates = texturePositions.capeLabymodRelative;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        capeTextureCoordinates = JSON.parse(JSON.stringify(capeTextureCoordinates)); // bad clone to keep the below scaling from affecting everything
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        console.log(capeTextureCoordinates);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        type CubeTextureKey = 'left' | 'right' | 'front' | 'back' | 'top' | 'bottom'
 | 
				
			||||||
 | 
					        // Multiply coordinates by image dimensions
 | 
				
			||||||
 | 
					        for (let cord in capeTextureCoordinates) {
 | 
				
			||||||
 | 
					            let key = cord as CubeTextureKey;
 | 
				
			||||||
 | 
					            capeTextureCoordinates[key].x *= capeTexture.image.width;
 | 
				
			||||||
 | 
					            capeTextureCoordinates[key].w *= capeTexture.image.width;
 | 
				
			||||||
 | 
					            capeTextureCoordinates[key].y *= capeTexture.image.height;
 | 
				
			||||||
 | 
					            capeTextureCoordinates[key].h *= capeTexture.image.height;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        console.log(capeTextureCoordinates);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let capeGroup = new THREE.Object3D();
 | 
				
			||||||
 | 
					        capeGroup.name = 'capeGroup';
 | 
				
			||||||
 | 
					        capeGroup.position.x = 0;
 | 
				
			||||||
 | 
					        capeGroup.position.y = 16;
 | 
				
			||||||
 | 
					        capeGroup.position.z = -2.5;
 | 
				
			||||||
 | 
					        capeGroup.translateOnAxis(new THREE.Vector3(0, 1, 0), 8);
 | 
				
			||||||
 | 
					        capeGroup.translateOnAxis(new THREE.Vector3(0, 0, 1), 0.5);
 | 
				
			||||||
 | 
					        let cape = createCube(capeTexture,
 | 
				
			||||||
 | 
					            10, 16, 1,
 | 
				
			||||||
 | 
					            capeTextureCoordinates,
 | 
				
			||||||
 | 
					            false,
 | 
				
			||||||
 | 
					            'cape');
 | 
				
			||||||
 | 
					        cape.rotation.x = toRadians(10); // slight backward angle
 | 
				
			||||||
 | 
					        cape.translateOnAxis(new THREE.Vector3(0, 1, 0), -8);
 | 
				
			||||||
 | 
					        cape.translateOnAxis(new THREE.Vector3(0, 0, 1), -0.5);
 | 
				
			||||||
 | 
					        cape.rotation.y = toRadians(180); // flip front&back to be correct
 | 
				
			||||||
 | 
					        capeGroup.add(cape);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        playerGroup.add(capeGroup);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return playerGroup;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function toRadians(angle: number) {
 | 
				
			||||||
 | 
					    return angle * (Math.PI / 180);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										25
									
								
								frontend/src/types.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type AppState = {
 | 
				
			||||||
 | 
					    login: boolean
 | 
				
			||||||
 | 
					    accessToken: string
 | 
				
			||||||
 | 
					    tokenValid: boolean
 | 
				
			||||||
 | 
					    loginTime: number
 | 
				
			||||||
 | 
					    profileName: string
 | 
				
			||||||
 | 
					    uuid: string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2022. Gardel <sunxinao@hotmail.com> and contributors
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 * it under the terms of the GNU Affero General Public License as published by
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
@@ -15,37 +15,39 @@
 | 
				
			|||||||
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
html, body {
 | 
					 | 
				
			||||||
  height: 100%;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
body {
 | 
					 | 
				
			||||||
  font-family: 'Roboto';
 | 
					 | 
				
			||||||
  margin: 0;
 | 
					 | 
				
			||||||
  padding-top: 0.1px;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
.header {
 | 
					.header {
 | 
				
			||||||
    text-align: center;
 | 
					    text-align: center;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.username,
 | 
					.user-card {
 | 
				
			||||||
.profileName,
 | 
					    padding: 14px 24px;
 | 
				
			||||||
.password,
 | 
					    margin: auto;
 | 
				
			||||||
.profileName-helper,
 | 
					}
 | 
				
			||||||
.password-helper {
 | 
					
 | 
				
			||||||
 | 
					.model,
 | 
				
			||||||
 | 
					.textureType,
 | 
				
			||||||
 | 
					.url,
 | 
				
			||||||
 | 
					.changeTo {
 | 
				
			||||||
    display: block;
 | 
					    display: block;
 | 
				
			||||||
  width: 300px;
 | 
					    width: 87%;
 | 
				
			||||||
 | 
					    margin: 20px auto;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.file {
 | 
				
			||||||
 | 
					    display: flex;
 | 
				
			||||||
 | 
					    width: 87%;
 | 
				
			||||||
    margin: 20px auto;
 | 
					    margin: 20px auto;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.button-container {
 | 
					.button-container {
 | 
				
			||||||
    display: flex;
 | 
					    display: flex;
 | 
				
			||||||
    justify-content: flex-end;
 | 
					    justify-content: flex-end;
 | 
				
			||||||
  width: 300px;
 | 
					    width: 87%;
 | 
				
			||||||
    margin: auto;
 | 
					    margin: auto;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.button-container button {
 | 
					.button-container button {
 | 
				
			||||||
    margin: 3px;
 | 
					    margin: 3px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										474
									
								
								frontend/src/user.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,474 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import React from 'react';
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					    Box,
 | 
				
			||||||
 | 
					    Collapse,
 | 
				
			||||||
 | 
					    Container,
 | 
				
			||||||
 | 
					    Fade,
 | 
				
			||||||
 | 
					    FilledInput,
 | 
				
			||||||
 | 
					    FormControl,
 | 
				
			||||||
 | 
					    FormControlLabel,
 | 
				
			||||||
 | 
					    FormLabel,
 | 
				
			||||||
 | 
					    IconButton,
 | 
				
			||||||
 | 
					    InputAdornment,
 | 
				
			||||||
 | 
					    InputLabel,
 | 
				
			||||||
 | 
					    Paper,
 | 
				
			||||||
 | 
					    Radio,
 | 
				
			||||||
 | 
					    RadioGroup,
 | 
				
			||||||
 | 
					    TextField
 | 
				
			||||||
 | 
					} from '@mui/material';
 | 
				
			||||||
 | 
					import './user.css';
 | 
				
			||||||
 | 
					import {AppState} from './types';
 | 
				
			||||||
 | 
					import {Delete} from '@mui/icons-material';
 | 
				
			||||||
 | 
					import Button from '@mui/material/Button';
 | 
				
			||||||
 | 
					import {useSnackbar} from 'notistack';
 | 
				
			||||||
 | 
					import {FocusedShowHelperText} from './components';
 | 
				
			||||||
 | 
					import {SubmitHandler, useForm} from 'react-hook-form';
 | 
				
			||||||
 | 
					import axios from 'axios';
 | 
				
			||||||
 | 
					import SkinRender from './skinrender/skin-render';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function handleMouseDown(event: React.MouseEvent<HTMLButtonElement>) {
 | 
				
			||||||
 | 
					    event.preventDefault();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function UploadTextureForm(props: {
 | 
				
			||||||
 | 
					    appData: AppState,
 | 
				
			||||||
 | 
					    setAppData: React.Dispatch<React.SetStateAction<AppState>>,
 | 
				
			||||||
 | 
					    skinData: SkinData | null,
 | 
				
			||||||
 | 
					    setSkinData: React.Dispatch<React.SetStateAction<SkinData | null>>
 | 
				
			||||||
 | 
					}) {
 | 
				
			||||||
 | 
					    const {appData, skinData, setSkinData} = props;
 | 
				
			||||||
 | 
					    const [submitting, setSubmitting] = React.useState(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const {enqueueSnackbar} = useSnackbar();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const fileInputElem = React.useRef<HTMLInputElement>(null);
 | 
				
			||||||
 | 
					    const [filePath, setFilePath] = React.useState('');
 | 
				
			||||||
 | 
					    const handleFilePathChange = (event: React.ChangeEvent<HTMLInputElement>) => {
 | 
				
			||||||
 | 
					        setFilePath(event.target.value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (skinData) {
 | 
				
			||||||
 | 
					            if (type == 'cape' && skinData.capeUrl?.startsWith('blob:')) {
 | 
				
			||||||
 | 
					                URL.revokeObjectURL(skinData.capeUrl);
 | 
				
			||||||
 | 
					            } else if (skinData.skinUrl.startsWith('blob:')) {
 | 
				
			||||||
 | 
					                URL.revokeObjectURL(skinData.skinUrl);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const fileInput = event.target;
 | 
				
			||||||
 | 
					        const fileBlob = fileInput.files?.length ? fileInput.files[0] : null;
 | 
				
			||||||
 | 
					        if (fileBlob && skinData) {
 | 
				
			||||||
 | 
					            let data: SkinData = {
 | 
				
			||||||
 | 
					                ...skinData
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            const fakeUrl = URL.createObjectURL(fileBlob);
 | 
				
			||||||
 | 
					            if (type == 'cape') {
 | 
				
			||||||
 | 
					                data.capeUrl = fakeUrl;
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                data.slim = model == 'slim';
 | 
				
			||||||
 | 
					                data.skinUrl = fakeUrl;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            setSkinData(data);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const [url, setUrl] = React.useState('');
 | 
				
			||||||
 | 
					    const handleUrlChange = (event: React.ChangeEvent<HTMLInputElement>) => {
 | 
				
			||||||
 | 
					        setUrl(event.target.value);
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const [type, setType] = React.useState('skin');
 | 
				
			||||||
 | 
					    const handleTypeChange = (event: React.ChangeEvent<HTMLInputElement>) => {
 | 
				
			||||||
 | 
					        setType(event.target.value);
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const [model, setModel] = React.useState('default');
 | 
				
			||||||
 | 
					    const handleModelChange = (event: React.ChangeEvent<HTMLInputElement>) => {
 | 
				
			||||||
 | 
					        setModel(event.target.value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (skinData) {
 | 
				
			||||||
 | 
					            setSkinData({
 | 
				
			||||||
 | 
					                ...skinData,
 | 
				
			||||||
 | 
					                slim: event.target.value == 'slim'
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const uploadTexture = (event: React.FormEvent) => {
 | 
				
			||||||
 | 
					        event.preventDefault();
 | 
				
			||||||
 | 
					        const fileInput = fileInputElem.current;
 | 
				
			||||||
 | 
					        if (fileInput == null) {
 | 
				
			||||||
 | 
					            console.error('#file-input-real is not a valid element');
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        setSubmitting(true);
 | 
				
			||||||
 | 
					        const fileBlob = fileInput.files?.length ? fileInput.files[0] : null;
 | 
				
			||||||
 | 
					        if (filePath && fileBlob) {
 | 
				
			||||||
 | 
					            const formData = new FormData();
 | 
				
			||||||
 | 
					            formData.append('model', model);
 | 
				
			||||||
 | 
					            formData.append('file', fileBlob);
 | 
				
			||||||
 | 
					            axios.put(`/api/user/profile/${appData.uuid}/${type}`, formData, {
 | 
				
			||||||
 | 
					                headers: {
 | 
				
			||||||
 | 
					                    'Authorization': 'Bearer ' + appData.accessToken
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }).then(() => {
 | 
				
			||||||
 | 
					                enqueueSnackbar('上传成功', {variant: 'success'});
 | 
				
			||||||
 | 
					            }).catch(e => {
 | 
				
			||||||
 | 
					                const response = e.response;
 | 
				
			||||||
 | 
					                if (response && response.data) {
 | 
				
			||||||
 | 
					                    enqueueSnackbar(response.data.errorMessage, {variant: 'error'});
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    enqueueSnackbar('网络错误:' + e.message, {variant: 'error'});
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }).finally(() => setSubmitting(false));
 | 
				
			||||||
 | 
					        } else if (url) {
 | 
				
			||||||
 | 
					            axios.post(`/api/user/profile/${appData.uuid}/${type}`, {model, url}, {
 | 
				
			||||||
 | 
					                headers: {
 | 
				
			||||||
 | 
					                    'Authorization': 'Bearer ' + appData.accessToken
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }).then(() => {
 | 
				
			||||||
 | 
					                enqueueSnackbar('上传成功', {variant: 'success'});
 | 
				
			||||||
 | 
					                axios.get('/sessionserver/session/minecraft/profile/' + appData.uuid).then(response => {
 | 
				
			||||||
 | 
					                    let texturesProp = response.data.properties.find((v: any) => v.name == 'textures');
 | 
				
			||||||
 | 
					                    let profile: any = {};
 | 
				
			||||||
 | 
					                    if (texturesProp) {
 | 
				
			||||||
 | 
					                        profile = JSON.parse(window.atob(texturesProp.value));
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    if (profile.textures) {
 | 
				
			||||||
 | 
					                        let data: SkinData = {
 | 
				
			||||||
 | 
					                            skinUrl: ''
 | 
				
			||||||
 | 
					                        };
 | 
				
			||||||
 | 
					                        if (profile.textures.SKIN) {
 | 
				
			||||||
 | 
					                            data.skinUrl = profile.textures.SKIN.url;
 | 
				
			||||||
 | 
					                            data.slim = profile.textures.SKIN.metadata ? profile.textures.SKIN.metadata.model == 'slim' : false;
 | 
				
			||||||
 | 
					                        } else {
 | 
				
			||||||
 | 
					                            let index = getUUIDHashCode(appData.uuid) % DEFAULT_SKINS.length;
 | 
				
			||||||
 | 
					                            data.skinUrl = DEFAULT_SKINS[index].skinUrl;
 | 
				
			||||||
 | 
					                            data.slim = DEFAULT_SKINS[index].slim;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        if (profile.textures.CAPE) {
 | 
				
			||||||
 | 
					                           data.capeUrl = profile.textures.CAPE.url;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        setSkinData(data);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            }).catch(e => {
 | 
				
			||||||
 | 
					                const response = e.response;
 | 
				
			||||||
 | 
					                if (response && response.data) {
 | 
				
			||||||
 | 
					                    enqueueSnackbar(response.data.errorMessage, {variant: 'error'});
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    enqueueSnackbar('网络错误:' + e.message, {variant: 'error'});
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }).finally(() => setSubmitting(false));
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            enqueueSnackbar('未选择文件', {variant: 'warning'});
 | 
				
			||||||
 | 
					            setSubmitting(false);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const deleteTexture = () => {
 | 
				
			||||||
 | 
					        setSubmitting(true);
 | 
				
			||||||
 | 
					        axios.delete(`/api/user/profile/${appData.uuid}/${type}`, {
 | 
				
			||||||
 | 
					            headers: {
 | 
				
			||||||
 | 
					                'Authorization': 'Bearer ' + appData.accessToken
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }).then(() => {
 | 
				
			||||||
 | 
					            enqueueSnackbar('删除成功', {variant: 'success'});
 | 
				
			||||||
 | 
					            if (skinData != null) {
 | 
				
			||||||
 | 
					                if (type == 'cape') {
 | 
				
			||||||
 | 
					                    setSkinData({
 | 
				
			||||||
 | 
					                        ...skinData,
 | 
				
			||||||
 | 
					                        capeUrl: undefined
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    // 显示默认材质
 | 
				
			||||||
 | 
					                    let index = getUUIDHashCode(appData.uuid) % DEFAULT_SKINS.length;
 | 
				
			||||||
 | 
					                    setSkinData({
 | 
				
			||||||
 | 
					                        ...DEFAULT_SKINS[index],
 | 
				
			||||||
 | 
					                        capeUrl: skinData.capeUrl
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }).catch(e => {
 | 
				
			||||||
 | 
					            const response = e.response;
 | 
				
			||||||
 | 
					            if (response && response.data) {
 | 
				
			||||||
 | 
					                enqueueSnackbar(response.data.errorMessage, {variant: 'error'});
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                enqueueSnackbar('网络错误:' + e.message, {variant: 'error'});
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }).finally(() => setSubmitting(false));
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // noinspection JSUnusedGlobalSymbols
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        <>
 | 
				
			||||||
 | 
					            <section className="header">
 | 
				
			||||||
 | 
					                <h3>上传材质</h3>
 | 
				
			||||||
 | 
					            </section>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <Box component="form" autoComplete="off" onSubmit={uploadTexture}>
 | 
				
			||||||
 | 
					                <Box component="div" width="50%" boxSizing="border-box" display="inline-block">
 | 
				
			||||||
 | 
					                    <FormControl>
 | 
				
			||||||
 | 
					                        <FormLabel id="texture-type-group-label">材质类别: </FormLabel>
 | 
				
			||||||
 | 
					                        <RadioGroup
 | 
				
			||||||
 | 
					                            row
 | 
				
			||||||
 | 
					                            aria-labelledby="texture-type-group-label"
 | 
				
			||||||
 | 
					                            value={type}
 | 
				
			||||||
 | 
					                            onChange={handleTypeChange}
 | 
				
			||||||
 | 
					                            name="type">
 | 
				
			||||||
 | 
					                            <FormControlLabel value="skin" control={<Radio/>} label="皮肤"/>
 | 
				
			||||||
 | 
					                            <FormControlLabel value="cape" control={<Radio/>} label="披风"/>
 | 
				
			||||||
 | 
					                        </RadioGroup>
 | 
				
			||||||
 | 
					                    </FormControl>
 | 
				
			||||||
 | 
					                </Box>
 | 
				
			||||||
 | 
					                <Fade in={type == 'skin'}>
 | 
				
			||||||
 | 
					                    <Box component="div" width="50%" boxSizing="border-box" display="inline-block">
 | 
				
			||||||
 | 
					                        <FormControl>
 | 
				
			||||||
 | 
					                            <FormLabel id="texture-model-group-label">材质模型: </FormLabel>
 | 
				
			||||||
 | 
					                            <RadioGroup
 | 
				
			||||||
 | 
					                                row
 | 
				
			||||||
 | 
					                                aria-labelledby="texture-model-group-label"
 | 
				
			||||||
 | 
					                                value={model}
 | 
				
			||||||
 | 
					                                onChange={handleModelChange}
 | 
				
			||||||
 | 
					                                name="model">
 | 
				
			||||||
 | 
					                                <FormControlLabel value="default" control={<Radio/>} label="Steve"/>
 | 
				
			||||||
 | 
					                                <FormControlLabel value="slim" control={<Radio/>} label="Alex"/>
 | 
				
			||||||
 | 
					                            </RadioGroup>
 | 
				
			||||||
 | 
					                        </FormControl>
 | 
				
			||||||
 | 
					                    </Box>
 | 
				
			||||||
 | 
					                </Fade>
 | 
				
			||||||
 | 
					                <Collapse in={!filePath} className="url">
 | 
				
			||||||
 | 
					                    <TextField
 | 
				
			||||||
 | 
					                        id="url-input"
 | 
				
			||||||
 | 
					                        name="url"
 | 
				
			||||||
 | 
					                        fullWidth
 | 
				
			||||||
 | 
					                        label="材质 URL"
 | 
				
			||||||
 | 
					                        variant="filled"
 | 
				
			||||||
 | 
					                        required={!filePath}
 | 
				
			||||||
 | 
					                        type="url"
 | 
				
			||||||
 | 
					                        value={url}
 | 
				
			||||||
 | 
					                        onChange={handleUrlChange}
 | 
				
			||||||
 | 
					                    />
 | 
				
			||||||
 | 
					                </Collapse>
 | 
				
			||||||
 | 
					                <Collapse in={!url} className="file">
 | 
				
			||||||
 | 
					                    <FormControl fullWidth variant="filled" required={!url}>
 | 
				
			||||||
 | 
					                        <InputLabel htmlFor="file-input">或者选择一个图片</InputLabel>
 | 
				
			||||||
 | 
					                        <FilledInput
 | 
				
			||||||
 | 
					                            id="file-input"
 | 
				
			||||||
 | 
					                            required={!url}
 | 
				
			||||||
 | 
					                            endAdornment={
 | 
				
			||||||
 | 
					                                <InputAdornment position="end">
 | 
				
			||||||
 | 
					                                    <IconButton
 | 
				
			||||||
 | 
					                                        aria-label="清空选择"
 | 
				
			||||||
 | 
					                                        edge="end"
 | 
				
			||||||
 | 
					                                        onMouseDown={handleMouseDown}
 | 
				
			||||||
 | 
					                                        onClick={() => setFilePath('')}>
 | 
				
			||||||
 | 
					                                        <Delete/>
 | 
				
			||||||
 | 
					                                    </IconButton>
 | 
				
			||||||
 | 
					                                </InputAdornment>
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            value={filePath}
 | 
				
			||||||
 | 
					                            inputProps={{
 | 
				
			||||||
 | 
					                                onClick: () => fileInputElem.current?.click()
 | 
				
			||||||
 | 
					                            }}
 | 
				
			||||||
 | 
					                        />
 | 
				
			||||||
 | 
					                        <input id="file-input-real" type="file" name="file" hidden ref={fileInputElem} accept="image/*" value={filePath} onChange={handleFilePathChange}/>
 | 
				
			||||||
 | 
					                    </FormControl>
 | 
				
			||||||
 | 
					                </Collapse>
 | 
				
			||||||
 | 
					                <div className="button-container">
 | 
				
			||||||
 | 
					                    <Button variant="contained" type="submit" disabled={submitting}>上传</Button>
 | 
				
			||||||
 | 
					                    <Button variant="contained" onClick={deleteTexture} disabled={submitting}>删除材质</Button>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            </Box>
 | 
				
			||||||
 | 
					        </>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ChangeProfileInputs = {
 | 
				
			||||||
 | 
					    changeTo: string
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function ChangeProfileForm(props: { appData: AppState, setAppData: React.Dispatch<React.SetStateAction<AppState>> }) {
 | 
				
			||||||
 | 
					    const {appData, setAppData} = props;
 | 
				
			||||||
 | 
					    const setProfileName = (profileName: string) => {
 | 
				
			||||||
 | 
					        if (appData.profileName != profileName) {
 | 
				
			||||||
 | 
					            setAppData(oldData => {
 | 
				
			||||||
 | 
					                return {
 | 
				
			||||||
 | 
					                    ...oldData,
 | 
				
			||||||
 | 
					                    profileName
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const [submitting, setSubmitting] = React.useState(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const {enqueueSnackbar} = useSnackbar();
 | 
				
			||||||
 | 
					    const {register, handleSubmit, formState: {errors}} = useForm<ChangeProfileInputs>();
 | 
				
			||||||
 | 
					    const onSubmit: SubmitHandler<ChangeProfileInputs> = data => {
 | 
				
			||||||
 | 
					        setSubmitting(true);
 | 
				
			||||||
 | 
					        axios.post('/authserver/change', {
 | 
				
			||||||
 | 
					            accessToken: appData.accessToken,
 | 
				
			||||||
 | 
					            changeTo: data.changeTo
 | 
				
			||||||
 | 
					        }).then(() => {
 | 
				
			||||||
 | 
					            enqueueSnackbar('更改成功', {variant: 'success'});
 | 
				
			||||||
 | 
					            setProfileName(data.changeTo);
 | 
				
			||||||
 | 
					        }).catch(e => {
 | 
				
			||||||
 | 
					            const response = e.response;
 | 
				
			||||||
 | 
					            if (response && response.data) {
 | 
				
			||||||
 | 
					                let errorMessage = response.data.errorMessage;
 | 
				
			||||||
 | 
					                let message = '更改失败: ' + errorMessage;
 | 
				
			||||||
 | 
					                if (errorMessage === 'profileName exist') {
 | 
				
			||||||
 | 
					                    message = '更改失败: 角色名已存在';
 | 
				
			||||||
 | 
					                } else if (errorMessage === 'profileName duplicate') {
 | 
				
			||||||
 | 
					                    message = '更改失败: 角色名与正版用户冲突';
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                enqueueSnackbar(message, {variant: 'error'});
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                enqueueSnackbar('网络错误:' + e.message, {variant: 'error'});
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }).finally(() => setSubmitting(false));
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        <>
 | 
				
			||||||
 | 
					            <section className="header">
 | 
				
			||||||
 | 
					                <h3>更改角色名</h3>
 | 
				
			||||||
 | 
					            </section>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <Box component="form" autoComplete="off" onSubmit={handleSubmit(onSubmit)}>
 | 
				
			||||||
 | 
					                <div className="changeTo">
 | 
				
			||||||
 | 
					                    <FormControl fullWidth variant="filled" required error={errors.changeTo != null}>
 | 
				
			||||||
 | 
					                        <InputLabel htmlFor="changeTo-input">角色名</InputLabel>
 | 
				
			||||||
 | 
					                        <FilledInput
 | 
				
			||||||
 | 
					                            id="changeTo-input"
 | 
				
			||||||
 | 
					                            name="changeTo"
 | 
				
			||||||
 | 
					                            defaultValue={appData.profileName}
 | 
				
			||||||
 | 
					                            required
 | 
				
			||||||
 | 
					                            inputProps={{
 | 
				
			||||||
 | 
					                                minLength: '2', maxLength: 16,
 | 
				
			||||||
 | 
					                                ...register('changeTo', {required: true, minLength: 2, pattern: /^[a-zA-Z0-9_]{1,16}$/, maxLength: 16})
 | 
				
			||||||
 | 
					                            }}
 | 
				
			||||||
 | 
					                        />
 | 
				
			||||||
 | 
					                        <FocusedShowHelperText id="profileName-input-helper-text">字母,数字或下划线</FocusedShowHelperText>
 | 
				
			||||||
 | 
					                    </FormControl>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div className="button-container">
 | 
				
			||||||
 | 
					                    <Button variant="contained" type="submit" disabled={submitting}>更改</Button>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            </Box>
 | 
				
			||||||
 | 
					        </>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SkinData = {
 | 
				
			||||||
 | 
					    skinUrl: string
 | 
				
			||||||
 | 
					    capeUrl?: string
 | 
				
			||||||
 | 
					    slim?: boolean
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const DEFAULT_SKINS: SkinData[] = [
 | 
				
			||||||
 | 
					    {skinUrl: 'player/slim/alex.png', slim: true},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/slim/ari.png', slim: true},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/slim/efe.png', slim: true},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/slim/kai.png', slim: true},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/slim/makena.png', slim: true},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/slim/noor.png', slim: true},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/slim/steve.png', slim: true},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/slim/sunny.png', slim: true},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/slim/zuri.png', slim: true},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    {skinUrl: 'player/wide/alex.png'},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/wide/ari.png'},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/wide/efe.png'},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/wide/kai.png'},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/wide/makena.png'},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/wide/noor.png'},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/wide/steve.png'},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/wide/sunny.png'},
 | 
				
			||||||
 | 
					    {skinUrl: 'player/wide/zuri.png'},
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function User(props: { appData: AppState, setAppData: React.Dispatch<React.SetStateAction<AppState>> }) {
 | 
				
			||||||
 | 
					    const {appData, setAppData} = props;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const [skinData, setSkinData] = React.useState<SkinData | null>(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    React.useEffect(() => {
 | 
				
			||||||
 | 
					        setSkinData(null);
 | 
				
			||||||
 | 
					        axios.get('/sessionserver/session/minecraft/profile/' + appData.uuid).then(response => {
 | 
				
			||||||
 | 
					            let texturesProp = response.data.properties.find((v: any) => v.name == 'textures');
 | 
				
			||||||
 | 
					            let profile: any = {};
 | 
				
			||||||
 | 
					            if (texturesProp) {
 | 
				
			||||||
 | 
					                profile = JSON.parse(window.atob(texturesProp.value));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (profile.textures && profile.textures.SKIN) {
 | 
				
			||||||
 | 
					                let skinUrl = profile.textures.SKIN.url;
 | 
				
			||||||
 | 
					                let slim = profile.textures.SKIN.metadata ? profile.textures.SKIN.metadata.model == 'slim' : false;
 | 
				
			||||||
 | 
					                let capeUrl = undefined;
 | 
				
			||||||
 | 
					                if (profile.textures.CAPE) {
 | 
				
			||||||
 | 
					                    capeUrl = profile.textures.CAPE.url;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                setSkinData({
 | 
				
			||||||
 | 
					                    skinUrl,
 | 
				
			||||||
 | 
					                    capeUrl,
 | 
				
			||||||
 | 
					                    slim
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            } else if (profile.textures && profile.textures.CAPE) {
 | 
				
			||||||
 | 
					                // 显示默认材质
 | 
				
			||||||
 | 
					                let index = getUUIDHashCode(appData.uuid) % DEFAULT_SKINS.length;
 | 
				
			||||||
 | 
					                setSkinData({
 | 
				
			||||||
 | 
					                    ...DEFAULT_SKINS[index],
 | 
				
			||||||
 | 
					                    capeUrl: profile.textures.CAPE.url
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                // 显示默认材质
 | 
				
			||||||
 | 
					                let index = getUUIDHashCode(appData.uuid) % DEFAULT_SKINS.length;
 | 
				
			||||||
 | 
					                setSkinData(DEFAULT_SKINS[index]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }, [appData]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        <Container maxWidth={'sm'}>
 | 
				
			||||||
 | 
					            <Paper className={'user-card'}>
 | 
				
			||||||
 | 
					                <section className="header">
 | 
				
			||||||
 | 
					                    <h1>简陋信息页</h1>
 | 
				
			||||||
 | 
					                </section>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <UploadTextureForm appData={appData} setAppData={setAppData} skinData={skinData} setSkinData={setSkinData}/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                {skinData && <SkinRender skinUrl={skinData.skinUrl} capeUrl={skinData.capeUrl} slim={skinData.slim}/>}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <ChangeProfileForm appData={appData} setAppData={setAppData}/>
 | 
				
			||||||
 | 
					            </Paper>
 | 
				
			||||||
 | 
					        </Container>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function getUUIDHashCode(uuid: string) {
 | 
				
			||||||
 | 
					    const uuidNoDash = uuid.replace(/-/g, '');
 | 
				
			||||||
 | 
					    const mostMost = parseInt(uuidNoDash.substring(0, 8), 16);
 | 
				
			||||||
 | 
					    const mostLeast = parseInt(uuidNoDash.substring(8, 16), 16);
 | 
				
			||||||
 | 
					    const leastMost = parseInt(uuidNoDash.substring(16, 24), 16);
 | 
				
			||||||
 | 
					    const leastLeast = parseInt(uuidNoDash.substring(24, 32), 16);
 | 
				
			||||||
 | 
					    return mostMost ^ mostLeast ^ leastMost ^ leastLeast;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default User;
 | 
				
			||||||
							
								
								
									
										18
									
								
								frontend/src/vite-env.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// <reference types="vite/client" />
 | 
				
			||||||
							
								
								
									
										21
									
								
								frontend/tsconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "compilerOptions": {
 | 
				
			||||||
 | 
					    "target": "ESNext",
 | 
				
			||||||
 | 
					    "useDefineForClassFields": true,
 | 
				
			||||||
 | 
					    "lib": ["DOM", "DOM.Iterable", "ESNext"],
 | 
				
			||||||
 | 
					    "allowJs": false,
 | 
				
			||||||
 | 
					    "skipLibCheck": true,
 | 
				
			||||||
 | 
					    "esModuleInterop": false,
 | 
				
			||||||
 | 
					    "allowSyntheticDefaultImports": true,
 | 
				
			||||||
 | 
					    "strict": true,
 | 
				
			||||||
 | 
					    "forceConsistentCasingInFileNames": true,
 | 
				
			||||||
 | 
					    "module": "ESNext",
 | 
				
			||||||
 | 
					    "moduleResolution": "Node",
 | 
				
			||||||
 | 
					    "resolveJsonModule": true,
 | 
				
			||||||
 | 
					    "isolatedModules": true,
 | 
				
			||||||
 | 
					    "noEmit": true,
 | 
				
			||||||
 | 
					    "jsx": "react-jsx"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "include": ["src"],
 | 
				
			||||||
 | 
					  "references": [{ "path": "./tsconfig.node.json" }]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										9
									
								
								frontend/tsconfig.node.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "compilerOptions": {
 | 
				
			||||||
 | 
					    "composite": true,
 | 
				
			||||||
 | 
					    "module": "ESNext",
 | 
				
			||||||
 | 
					    "moduleResolution": "Node",
 | 
				
			||||||
 | 
					    "allowSyntheticDefaultImports": true
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "include": ["vite.config.ts"]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										33
									
								
								frontend/vite.config.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { defineConfig } from 'vite'
 | 
				
			||||||
 | 
					import react from '@vitejs/plugin-react'
 | 
				
			||||||
 | 
					import mockDevServerPlugin from 'vite-plugin-mock-dev-server'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://vitejs.dev/config/
 | 
				
			||||||
 | 
					export default defineConfig({
 | 
				
			||||||
 | 
					  plugins: [react(), mockDevServerPlugin()],
 | 
				
			||||||
 | 
					  server: {
 | 
				
			||||||
 | 
					    proxy: {
 | 
				
			||||||
 | 
					      '^/(authserver|users|sessionserver|textures|api|minecraftservices)': {
 | 
				
			||||||
 | 
					        target: 'http://localhost:8080'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  base: ''
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
							
								
								
									
										1981
									
								
								frontend/yarn.lock
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										47
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						@@ -2,35 +2,26 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
 | 
				
			|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
					github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
				
			||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 | 
					github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 | 
				
			||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
					github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
				
			||||||
github.com/gin-contrib/cors v1.3.1 h1:doAsuITavI4IOcd0Y19U4B+O0dNWihRyX//nn4sEmgA=
 | 
					 | 
				
			||||||
github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzFA61xsmDk=
 | 
					 | 
				
			||||||
github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g=
 | 
					github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g=
 | 
				
			||||||
github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs=
 | 
					github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs=
 | 
				
			||||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
 | 
					github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
 | 
				
			||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
 | 
					github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
 | 
				
			||||||
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
 | 
					 | 
				
			||||||
github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8=
 | 
					github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8=
 | 
				
			||||||
github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
 | 
					github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
 | 
				
			||||||
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
 | 
					github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
 | 
				
			||||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 | 
					github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 | 
				
			||||||
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
 | 
					 | 
				
			||||||
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
 | 
					github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
 | 
				
			||||||
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
 | 
					github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
 | 
				
			||||||
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
 | 
					 | 
				
			||||||
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
 | 
					github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
 | 
				
			||||||
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
 | 
					github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
 | 
				
			||||||
github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
 | 
					github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
 | 
				
			||||||
github.com/go-playground/validator/v10 v10.11.0 h1:0W+xRM511GY47Yy3bZUbJVitCNg2BOGlCyvTqsp/xIw=
 | 
					 | 
				
			||||||
github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
 | 
					 | 
				
			||||||
github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
 | 
					github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
 | 
				
			||||||
github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
 | 
					github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
 | 
				
			||||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
 | 
					github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
 | 
				
			||||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 | 
					github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 | 
				
			||||||
github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM=
 | 
					 | 
				
			||||||
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
 | 
					github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
 | 
				
			||||||
github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
 | 
					github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
 | 
				
			||||||
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
 | 
					github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
 | 
				
			||||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 | 
					 | 
				
			||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
 | 
					github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
 | 
				
			||||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
 | 
					github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
 | 
				
			||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 | 
					github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 | 
				
			||||||
@@ -44,7 +35,6 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr
 | 
				
			|||||||
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
					github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
				
			||||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 | 
					github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 | 
				
			||||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
					github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
				
			||||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
 | 
					 | 
				
			||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
 | 
					github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
 | 
				
			||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
 | 
					github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
 | 
				
			||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
 | 
					github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
 | 
				
			||||||
@@ -55,28 +45,20 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
 | 
				
			|||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 | 
					github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 | 
				
			||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 | 
					github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 | 
				
			||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
 | 
					github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
 | 
				
			||||||
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
 | 
					 | 
				
			||||||
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
 | 
					github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
 | 
				
			||||||
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
 | 
					github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
 | 
					 | 
				
			||||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
 | 
					 | 
				
			||||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
 | 
					github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
 | 
					github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
 | 
					github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
 | 
				
			||||||
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 | 
					github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 | 
				
			||||||
github.com/mattn/go-sqlite3 v1.14.13 h1:1tj15ngiFfcZzii7yd82foL+ks+ouQcj8j/TPq3fk1I=
 | 
					 | 
				
			||||||
github.com/mattn/go-sqlite3 v1.14.13/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 | 
					 | 
				
			||||||
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
 | 
					github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
 | 
				
			||||||
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
 | 
					github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
 | 
				
			||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 | 
					github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 | 
				
			||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
 | 
					github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
 | 
				
			||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 | 
					github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 | 
				
			||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
 | 
					 | 
				
			||||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
 | 
					github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
 | 
				
			||||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
 | 
					github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
 | 
				
			||||||
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
 | 
					github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
 | 
				
			||||||
github.com/pelletier/go-toml/v2 v2.0.2 h1:+jQXlF3scKIcSEKkdHzXhCTDLPFi5r1wnK6yPS+49Gw=
 | 
					 | 
				
			||||||
github.com/pelletier/go-toml/v2 v2.0.2/go.mod h1:MovirKjgVRESsAvNZlAjtFwV867yGuwRkXbG66OzopI=
 | 
					 | 
				
			||||||
github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
 | 
					github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
 | 
				
			||||||
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
 | 
					github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
 | 
				
			||||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
 | 
					github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
 | 
				
			||||||
@@ -88,41 +70,29 @@ github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6po
 | 
				
			|||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 | 
					github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 | 
				
			||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 | 
					github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 | 
				
			||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 | 
					github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 | 
				
			||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
 | 
					 | 
				
			||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
					github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
				
			||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
					github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
				
			||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
					github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
				
			||||||
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
 | 
					 | 
				
			||||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
 | 
					 | 
				
			||||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
 | 
					github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
 | 
				
			||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 | 
					github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 | 
				
			||||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
 | 
					 | 
				
			||||||
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
 | 
					github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
 | 
				
			||||||
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
 | 
					github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
 | 
				
			||||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
 | 
					 | 
				
			||||||
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
 | 
					github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
 | 
				
			||||||
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
 | 
					github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 | 
					golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 | 
					golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM=
 | 
					 | 
				
			||||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 | 
					 | 
				
			||||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
 | 
					golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 | 
					golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 | 
				
			||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
 | 
					golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
 | 
				
			||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 | 
					golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 | 
				
			||||||
golang.org/x/net v0.0.0-20220607020251-c690dde0001d h1:4SFsTMi4UahlKoloni7L4eYzhFRifURQLw+yv0QDCx8=
 | 
					 | 
				
			||||||
golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 | 
					 | 
				
			||||||
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI=
 | 
					golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI=
 | 
				
			||||||
golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
 | 
					golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					 | 
				
			||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d h1:Zu/JngovGLVi6t2J3nmAf3AoTDwuzw85YZ3b9o4yU7s=
 | 
					 | 
				
			||||||
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					 | 
				
			||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 h1:ohgcoMbSofXygzo6AD2I1kz3BFmW1QArPYTtwEM3UXc=
 | 
					golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 h1:ohgcoMbSofXygzo6AD2I1kz3BFmW1QArPYTtwEM3UXc=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
@@ -132,15 +102,12 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
				
			|||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
					golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
				
			||||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
 | 
					golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
 | 
				
			||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 | 
					golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 | 
				
			||||||
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 h1:Dpdu/EMxGMFgq0CeYMh4fazTD2vtlZRYE7wyynxJb9U=
 | 
					 | 
				
			||||||
golang.org/x/time v0.0.0-20220609170525-579cf78fd858/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 | 
					 | 
				
			||||||
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 h1:ftMN5LMiBFjbzleLqtoBZk7KdJwhuybIU+FckUHgoyQ=
 | 
					golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 h1:ftMN5LMiBFjbzleLqtoBZk7KdJwhuybIU+FckUHgoyQ=
 | 
				
			||||||
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 | 
					golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 | 
				
			||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 | 
					golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 | 
				
			||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
 | 
					golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
 | 
				
			||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
					golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
				
			||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
 | 
					google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
 | 
				
			||||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
 | 
					 | 
				
			||||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
 | 
					google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
 | 
				
			||||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
 | 
					google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
 | 
				
			||||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
 | 
					google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
 | 
				
			||||||
@@ -149,31 +116,19 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
 | 
				
			|||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
 | 
					gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
 | 
				
			||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
 | 
					gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
 | 
				
			||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
 | 
					gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
 | 
				
			||||||
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
 | 
					 | 
				
			||||||
gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
 | 
					 | 
				
			||||||
gopkg.in/ini.v1 v1.66.6 h1:LATuAqN/shcYAOkv3wl2L4rkaKqkcgTBQjOyYDvcPKI=
 | 
					 | 
				
			||||||
gopkg.in/ini.v1 v1.66.6/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
 | 
					 | 
				
			||||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
 | 
					gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
 | 
				
			||||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
 | 
					gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
 | 
				
			||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
					 | 
				
			||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 | 
					gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 | 
				
			||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
 | 
					gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
					gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
gorm.io/driver/mysql v1.3.5 h1:iWBTVW/8Ij5AG4e0G/zqzaJblYkBI1VIL1LG2HUGsvY=
 | 
					 | 
				
			||||||
gorm.io/driver/mysql v1.3.5/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
 | 
					 | 
				
			||||||
gorm.io/driver/mysql v1.3.6 h1:BhX1Y/RyALb+T9bZ3t07wLnPZBukt+IRkMn8UZSNbGM=
 | 
					gorm.io/driver/mysql v1.3.6 h1:BhX1Y/RyALb+T9bZ3t07wLnPZBukt+IRkMn8UZSNbGM=
 | 
				
			||||||
gorm.io/driver/mysql v1.3.6/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
 | 
					gorm.io/driver/mysql v1.3.6/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
 | 
				
			||||||
gorm.io/driver/sqlite v1.3.4 h1:NnFOPVfzi4CPsJPH4wXr6rMkPb4ElHEqKMvrsx9c9Fk=
 | 
					 | 
				
			||||||
gorm.io/driver/sqlite v1.3.4/go.mod h1:B+8GyC9K7VgzJAcrcXMRPdnMcck+8FgJynEehEPM16U=
 | 
					 | 
				
			||||||
gorm.io/driver/sqlite v1.3.6 h1:Fi8xNYCUplOqWiPa3/GuCeowRNBRGTf62DEmhMDHeQQ=
 | 
					gorm.io/driver/sqlite v1.3.6 h1:Fi8xNYCUplOqWiPa3/GuCeowRNBRGTf62DEmhMDHeQQ=
 | 
				
			||||||
gorm.io/driver/sqlite v1.3.6/go.mod h1:Sg1/pvnKtbQ7jLXxfZa+jSHvoX8hoZA8cn4xllOMTgE=
 | 
					gorm.io/driver/sqlite v1.3.6/go.mod h1:Sg1/pvnKtbQ7jLXxfZa+jSHvoX8hoZA8cn4xllOMTgE=
 | 
				
			||||||
gorm.io/gorm v1.23.4/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
 | 
					gorm.io/gorm v1.23.4/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
 | 
				
			||||||
gorm.io/gorm v1.23.6 h1:KFLdNgri4ExFFGTRGGFWON2P1ZN28+9SJRN8voOoYe0=
 | 
					 | 
				
			||||||
gorm.io/gorm v1.23.6/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
 | 
					 | 
				
			||||||
gorm.io/gorm v1.23.8 h1:h8sGJ+biDgBA1AD1Ha9gFCx7h8npU7AsLdlkX0n2TpE=
 | 
					 | 
				
			||||||
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
 | 
					gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
 | 
				
			||||||
gorm.io/gorm v1.23.9 h1:NSHG021i+MCznokeXR3udGaNyFyBQJW8MbjrJMVCfGw=
 | 
					gorm.io/gorm v1.23.9 h1:NSHG021i+MCznokeXR3udGaNyFyBQJW8MbjrJMVCfGw=
 | 
				
			||||||
gorm.io/gorm v1.23.9/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
 | 
					gorm.io/gorm v1.23.9/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										44
									
								
								main.go
									
									
									
									
									
								
							
							
						
						@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2022. Gardel <sunxinao@hotmail.com> and contributors
 | 
					 * Copyright (C) 2022-2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 * it under the terms of the GNU Affero General Public License as published by
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
@@ -22,14 +22,11 @@ import (
 | 
				
			|||||||
	"crypto/rand"
 | 
						"crypto/rand"
 | 
				
			||||||
	"crypto/rsa"
 | 
						"crypto/rsa"
 | 
				
			||||||
	"crypto/x509"
 | 
						"crypto/x509"
 | 
				
			||||||
	"embed"
 | 
					 | 
				
			||||||
	"encoding/pem"
 | 
						"encoding/pem"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
	"gopkg.in/ini.v1"
 | 
						"gopkg.in/ini.v1"
 | 
				
			||||||
	"gorm.io/gorm"
 | 
						"gorm.io/gorm"
 | 
				
			||||||
	"io/fs"
 | 
					 | 
				
			||||||
	"io/ioutil"
 | 
					 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
@@ -41,9 +38,6 @@ import (
 | 
				
			|||||||
	"yggdrasil-go/util"
 | 
						"yggdrasil-go/util"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//go:embed assets/*
 | 
					 | 
				
			||||||
var f embed.FS
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type MetaCfg struct {
 | 
					type MetaCfg struct {
 | 
				
			||||||
	ServerName            string   `ini:"server_name"`
 | 
						ServerName            string   `ini:"server_name"`
 | 
				
			||||||
	ImplementationName    string   `ini:"implementation_name"`
 | 
						ImplementationName    string   `ini:"implementation_name"`
 | 
				
			||||||
@@ -52,6 +46,11 @@ type MetaCfg struct {
 | 
				
			|||||||
	SkinRootUrl           string   `ini:"skin_root_url"`
 | 
						SkinRootUrl           string   `ini:"skin_root_url"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ServerCfg struct {
 | 
				
			||||||
 | 
						ServerAddress  string   `ini:"server_address"`
 | 
				
			||||||
 | 
						TrustedProxies []string `ini:"trusted_proxies"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	configFilePath := "config.ini"
 | 
						configFilePath := "config.ini"
 | 
				
			||||||
	cfg, err := ini.LooseLoad(configFilePath)
 | 
						cfg, err := ini.LooseLoad(configFilePath)
 | 
				
			||||||
@@ -61,7 +60,7 @@ func main() {
 | 
				
			|||||||
	meta := MetaCfg{
 | 
						meta := MetaCfg{
 | 
				
			||||||
		ServerName:            "A Mojang Yggdrasil Server",
 | 
							ServerName:            "A Mojang Yggdrasil Server",
 | 
				
			||||||
		ImplementationName:    "go-yggdrasil-server",
 | 
							ImplementationName:    "go-yggdrasil-server",
 | 
				
			||||||
		ImplementationVersion: "v0.1",
 | 
							ImplementationVersion: "v0.0.1",
 | 
				
			||||||
		SkinDomains:           []string{".example.com", "localhost"},
 | 
							SkinDomains:           []string{".example.com", "localhost"},
 | 
				
			||||||
		SkinRootUrl:           "http://localhost:8080",
 | 
							SkinRootUrl:           "http://localhost:8080",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -80,19 +79,32 @@ func main() {
 | 
				
			|||||||
	pathSection := cfg.Section("paths")
 | 
						pathSection := cfg.Section("paths")
 | 
				
			||||||
	privateKeyPath := pathSection.Key("private_key_file").MustString("private.pem")
 | 
						privateKeyPath := pathSection.Key("private_key_file").MustString("private.pem")
 | 
				
			||||||
	publicKeyPath := pathSection.Key("public_key_file").MustString("public.pem")
 | 
						publicKeyPath := pathSection.Key("public_key_file").MustString("public.pem")
 | 
				
			||||||
	address := cfg.Section("server").Key("server_address").MustString(":8080")
 | 
						serverCfg := ServerCfg{
 | 
				
			||||||
 | 
							ServerAddress: ":8080",
 | 
				
			||||||
 | 
							TrustedProxies: []string{
 | 
				
			||||||
 | 
								"127.0.0.0/8",
 | 
				
			||||||
 | 
								"10.0.0.0/8",
 | 
				
			||||||
 | 
								"192.168.0.0/16",
 | 
				
			||||||
 | 
								"172.16.0.0/12",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						err = cfg.Section("server").MapTo(&serverCfg)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Fatal("无法读取配置文件", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	_, err = os.Stat(configFilePath)
 | 
						_, err = os.Stat(configFilePath)
 | 
				
			||||||
	if err != nil && os.IsNotExist(err) {
 | 
						if err != nil && os.IsNotExist(err) {
 | 
				
			||||||
		log.Println("配置文件不存在,已使用默认配置")
 | 
							log.Println("配置文件不存在,已使用默认配置")
 | 
				
			||||||
		_ = cfg.Section("meta").ReflectFrom(&meta)
 | 
							_ = cfg.Section("meta").ReflectFrom(&meta)
 | 
				
			||||||
		_ = cfg.Section("database").ReflectFrom(&dbCfg)
 | 
							_ = cfg.Section("database").ReflectFrom(&dbCfg)
 | 
				
			||||||
 | 
							_ = cfg.Section("server").ReflectFrom(&serverCfg)
 | 
				
			||||||
		err = cfg.SaveToIndent(configFilePath, " ")
 | 
							err = cfg.SaveToIndent(configFilePath, " ")
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			log.Println("警告: 无法保存配置文件", err)
 | 
								log.Println("警告: 无法保存配置文件", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	checkRsaKeyFile(privateKeyPath, publicKeyPath)
 | 
						checkRsaKeyFile(privateKeyPath, publicKeyPath)
 | 
				
			||||||
	publicKeyContent, err := ioutil.ReadFile(publicKeyPath)
 | 
						publicKeyContent, err := os.ReadFile(publicKeyPath)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatal("无法读取公钥内容", err)
 | 
							log.Fatal("无法读取公钥内容", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -112,19 +124,19 @@ func main() {
 | 
				
			|||||||
	serverMeta.Meta.ImplementationVersion = meta.ImplementationVersion
 | 
						serverMeta.Meta.ImplementationVersion = meta.ImplementationVersion
 | 
				
			||||||
	serverMeta.Meta.FeatureNoMojangNamespace = true
 | 
						serverMeta.Meta.FeatureNoMojangNamespace = true
 | 
				
			||||||
	serverMeta.Meta.FeatureEnableProfileKey = true
 | 
						serverMeta.Meta.FeatureEnableProfileKey = true
 | 
				
			||||||
	serverMeta.Meta.Links.Homepage = meta.SkinRootUrl + "/profile/user.html"
 | 
						serverMeta.Meta.Links.Homepage = meta.SkinRootUrl + "/profile/"
 | 
				
			||||||
	serverMeta.Meta.Links.Register = meta.SkinRootUrl + "/profile/index.html"
 | 
						serverMeta.Meta.Links.Register = meta.SkinRootUrl + "/profile/"
 | 
				
			||||||
	serverMeta.SkinDomains = meta.SkinDomains
 | 
						serverMeta.SkinDomains = meta.SkinDomains
 | 
				
			||||||
	serverMeta.SignaturePublickey = string(publicKeyContent)
 | 
						serverMeta.SignaturePublickey = string(publicKeyContent)
 | 
				
			||||||
	r := gin.Default()
 | 
						r := gin.Default()
 | 
				
			||||||
	router.InitRouters(r, db, &serverMeta, meta.SkinRootUrl)
 | 
						err = r.SetTrustedProxies(serverCfg.TrustedProxies)
 | 
				
			||||||
	assetsFs, err := fs.Sub(f, "assets")
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatal(err)
 | 
							log.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	r.StaticFS("/profile", http.FS(assetsFs))
 | 
						router.InitRouters(r, db, &serverMeta, meta.SkinRootUrl)
 | 
				
			||||||
 | 
						r.Static("/profile", "assets")
 | 
				
			||||||
	srv := &http.Server{
 | 
						srv := &http.Server{
 | 
				
			||||||
		Addr:    address,
 | 
							Addr:    serverCfg.ServerAddress,
 | 
				
			||||||
		Handler: r,
 | 
							Handler: r,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2022. Gardel <sunxinao@hotmail.com> and contributors
 | 
					 * Copyright (C) 2022-2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 * it under the terms of the GNU Affero General Public License as published by
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
@@ -18,8 +18,11 @@
 | 
				
			|||||||
package router
 | 
					package router
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/base64"
 | 
				
			||||||
 | 
						"encoding/pem"
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
						"yggdrasil-go/util"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MetaInfo struct {
 | 
					type MetaInfo struct {
 | 
				
			||||||
@@ -42,17 +45,31 @@ type ServerMeta struct {
 | 
				
			|||||||
	SignaturePublickey string   `json:"signaturePublickey"`
 | 
						SignaturePublickey string   `json:"signaturePublickey"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type KeyPair struct {
 | 
				
			||||||
 | 
						PrivateKey string `json:"privateKey,omitempty"`
 | 
				
			||||||
 | 
						PublicKey  string `json:"publicKey,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PublicKeys struct {
 | 
				
			||||||
 | 
						ProfilePropertyKeys   []KeyPair `json:"profilePropertyKeys,omitempty"`
 | 
				
			||||||
 | 
						PlayerCertificateKeys []KeyPair `json:"playerCertificateKeys,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type HomeRouter interface {
 | 
					type HomeRouter interface {
 | 
				
			||||||
	Home(c *gin.Context)
 | 
						Home(c *gin.Context)
 | 
				
			||||||
 | 
						PublicKeys(c *gin.Context)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type homeRouterImpl struct {
 | 
					type homeRouterImpl struct {
 | 
				
			||||||
	serverMeta ServerMeta
 | 
						serverMeta ServerMeta
 | 
				
			||||||
 | 
						myPubKey   KeyPair
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewHomeRouter(meta *ServerMeta) HomeRouter {
 | 
					func NewHomeRouter(meta *ServerMeta) HomeRouter {
 | 
				
			||||||
 | 
						signaturePubKey, _ := pem.Decode([]byte(meta.SignaturePublickey))
 | 
				
			||||||
	homeRouter := homeRouterImpl{
 | 
						homeRouter := homeRouterImpl{
 | 
				
			||||||
		serverMeta: *meta,
 | 
							serverMeta: *meta,
 | 
				
			||||||
 | 
							myPubKey:   KeyPair{PublicKey: base64.StdEncoding.EncodeToString(signaturePubKey.Bytes)},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return &homeRouter
 | 
						return &homeRouter
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -61,3 +78,15 @@ func NewHomeRouter(meta *ServerMeta) HomeRouter {
 | 
				
			|||||||
func (h *homeRouterImpl) Home(c *gin.Context) {
 | 
					func (h *homeRouterImpl) Home(c *gin.Context) {
 | 
				
			||||||
	c.JSON(http.StatusOK, h.serverMeta)
 | 
						c.JSON(http.StatusOK, h.serverMeta)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *homeRouterImpl) PublicKeys(c *gin.Context) {
 | 
				
			||||||
 | 
						publicKeys := PublicKeys{}
 | 
				
			||||||
 | 
						err := util.GetObject("https://api.minecraftservices.com/publickeys", &publicKeys)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							util.HandleError(c, err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						publicKeys.ProfilePropertyKeys = append(publicKeys.ProfilePropertyKeys, h.myPubKey)
 | 
				
			||||||
 | 
						publicKeys.PlayerCertificateKeys = append(publicKeys.PlayerCertificateKeys, h.myPubKey)
 | 
				
			||||||
 | 
						c.JSON(http.StatusOK, publicKeys)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2022. Gardel <sunxinao@hotmail.com> and contributors
 | 
					 * Copyright (C) 2022-2023. Gardel <sunxinao@hotmail.com> and contributors
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 * it under the terms of the GNU Affero General Public License as published by
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
@@ -26,10 +26,6 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func InitRouters(router *gin.Engine, db *gorm.DB, meta *ServerMeta, skinRootUrl string) {
 | 
					func InitRouters(router *gin.Engine, db *gorm.DB, meta *ServerMeta, skinRootUrl string) {
 | 
				
			||||||
	err := router.SetTrustedProxies([]string{"127.0.0.1"})
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		panic(err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	router.Use(cors.New(cors.Config{
 | 
						router.Use(cors.New(cors.Config{
 | 
				
			||||||
		AllowAllOrigins:  true,
 | 
							AllowAllOrigins:  true,
 | 
				
			||||||
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "HEAD"},
 | 
							AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "HEAD"},
 | 
				
			||||||
@@ -76,5 +72,9 @@ func InitRouters(router *gin.Engine, db *gorm.DB, meta *ServerMeta, skinRootUrl
 | 
				
			|||||||
		api.DELETE("/user/profile/:uuid/:textureType", textureRouter.DeleteTexture)
 | 
							api.DELETE("/user/profile/:uuid/:textureType", textureRouter.DeleteTexture)
 | 
				
			||||||
		api.GET("/users/profiles/minecraft/:username", userRouter.UsernameToUUID)
 | 
							api.GET("/users/profiles/minecraft/:username", userRouter.UsernameToUUID)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	router.POST("/minecraftservices/player/certificates", userRouter.ProfileKey)
 | 
						minecraftservices := router.Group("/minecraftservices")
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							minecraftservices.POST("/player/certificates", userRouter.ProfileKey)
 | 
				
			||||||
 | 
							minecraftservices.GET("/publickeys", homeRouter.PublicKeys)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -178,28 +178,10 @@ func (u *userServiceImpl) Login(username string, password string, clientToken *s
 | 
				
			|||||||
				response.User = &userResponse
 | 
									response.User = &userResponse
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			return &response, nil
 | 
								return &response, nil
 | 
				
			||||||
		} else {
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil, util.NewForbiddenOperationError(util.MessageInvalidCredentials)
 | 
						return nil, util.NewForbiddenOperationError(util.MessageInvalidCredentials)
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		data := map[string]interface{}{
 | 
					 | 
				
			||||||
			"agent": map[string]interface{}{
 | 
					 | 
				
			||||||
				"name":    "Minecraft",
 | 
					 | 
				
			||||||
				"version": 1,
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			"username":    username,
 | 
					 | 
				
			||||||
			"password":    password,
 | 
					 | 
				
			||||||
			"clientToken": password,
 | 
					 | 
				
			||||||
			"requestUser": requestUser,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		loginResponse := LoginResponse{}
 | 
					 | 
				
			||||||
		err := util.PostObject("https://authserver.mojang.com/authenticate", data, &loginResponse)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return nil, err
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			return &loginResponse, nil
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (u *userServiceImpl) ChangeProfile(accessToken string, clientToken *string, changeTo string) error {
 | 
					func (u *userServiceImpl) ChangeProfile(accessToken string, clientToken *string, changeTo string) error {
 | 
				
			||||||
 
 | 
				
			|||||||