Github Dorisoy網盤專案

supermao12發表於2024-08-17

相關github地址
https://github.com/dorisoy/Dorisoy.Pan?tab=readme-ov-file

mysql8

sudo rpm -ivh mysql80-community-release-el7-5.noarch.rpm
wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
sudo yum install mysql-community-server --nogpgcheck
systemctl start mysqld
[root@centos7init yum.repos.d]# sudo grep 'temporary password' /var/log/mysqld.log
2024-08-17T01:20:53.607313Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: TwpqzkbqG0)j
mysql_secure_installation
Huawei@123  密碼設定高強度
mysql -uroot -pHuawei@123
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'Huawei@123';
Query OK, 0 rows affected (0.02 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
賦權

npm相關操作

PS C:\Users\supermao\Desktop\Dorisoy.Pan-main\UI> npm config set registry https://registry.npmmirror.com/
PS C:\Users\supermao\Desktop\Dorisoy.Pan-main\UI> npm config get registry
https://registry.npmmirror.com/
npm install 有時候npm install --force 也會管用,在不想理會依賴的時候
若報node版本錯誤則使用nvm install 版本 -> nvm use 版本
來改變版本號
https://github.com/coreybutler/nvm-windows/releases
npm run start

visual studio 2022


必須安裝此元件

"DocumentDbConnectionString": "Server=192.168.100.128;DataBase=dorisoy;User Id=root;Password=Huawei@123;"

無法找到回退包資料夾“D:\programme\share\NuGetPackages”
在此檔案裡更改對應路徑
Microsoft.VisualStudio.FallbackLocation.config

需安裝 PM> Install-Package Microsoft.EntityFrameworkCore.Tools

如果遇到重新生成解決方案出錯,NET7.0不滿足
則需要更新visual studio 使用 installer

將api設定為啟動項,然後啟動

修改原始碼,修改圖示

上傳失敗 修改原始碼

using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.IdentityModel.JsonWebTokens;
using Dorisoy.Pan.Data;
using Dorisoy.Pan.Data.Dto;

namespace Dorisoy.Pan.API.Helpers
{
    public static class JwtAuthenticationConfigurationExtension
    {
        public static void AddJwtAutheticationConfiguration(
            this IServiceCollection services,
            JwtSettings settings)
        {
            // Register Jwt as the Authentication service
            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = "JwtBearer";
                options.DefaultChallengeScheme = "JwtBearer";
            })
            .AddJwtBearer("JwtBearer", jwtBearerOptions =>
            {
                jwtBearerOptions.TokenValidationParameters =
              new TokenValidationParameters
              {
                  ValidateIssuerSigningKey = true,
                  IssuerSigningKey = new SymmetricSecurityKey(
                  Encoding.UTF8.GetBytes(settings.Key)),
                  ValidateIssuer = true,
                  ValidIssuer = settings.Issuer,

                  ValidateAudience = true,
                  ValidAudience = settings.Audience,

                  ValidateLifetime = true,
                  ClockSkew = TimeSpan.FromMinutes(
                         settings.MinutesToExpiration)
              };
                jwtBearerOptions.Events = new JwtBearerEvents
                {
                    OnTokenValidated = context =>
                    {
                        if (context.SecurityToken is Microsoft.IdentityModel.JsonWebTokens.JsonWebToken accessToken)
                        {
                            // 提取 userId 和 email
                            var userId = accessToken.Claims.FirstOrDefault(a => a.Type == JwtRegisteredClaimNames.Sub)?.Value;
                            var email = accessToken.Claims.FirstOrDefault(a => a.Type == "Email")?.Value;

                            if (!string.IsNullOrEmpty(userId))
                            {
                                context.HttpContext.Items["Id"] = userId;
                                var userInfoToken = context.HttpContext.RequestServices.GetRequiredService<UserInfoToken>();

                                // 增加異常處理確保 userId 是有效的 Guid
                                if (Guid.TryParse(userId, out var parsedUserId))
                                {
                                    userInfoToken.Id = parsedUserId;
                                }
                                else
                                {
                                    throw new SecurityTokenException("Invalid userId in token.");
                                }

                                userInfoToken.Email = email;
                            }
                            else
                            {
                                throw new SecurityTokenException("userId is missing in token.");
                            }
                        }
                        return Task.CompletedTask;
                    }
                };
            });
            services.AddAuthorization();
        }
    }
}

修復錯誤圖示



補充圖示路徑

相關文章