Github Dorisoy网盘项目

相关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();
        }
    }
}

修复错误图标



补充图标路径

posted @ 2024-08-17 19:34  supermao12  阅读(101)  评论(0编辑  收藏  举报