@@ -2,9 +2,31 @@ import { SETTINGS_KEY, ARTIFACT_REPOSITORY_KEY } from '@/constants';
22import { success , failed } from './response' ;
33import { InternalServerError } from '@/restful/errors' ;
44import $ from '@/core/app' ;
5- import Gist from '@/utils/gist' ;
5+ import Gist , { getGithubGistBaseURL } from '@/utils/gist' ;
66import { clearLogSettingsCache } from '@/utils/debug-logs' ;
77
8+ const ARTIFACT_STORE_SETTING_KEYS = [
9+ 'gistToken' ,
10+ 'githubProxy' ,
11+ 'githubApiUrl' ,
12+ 'defaultProxy' ,
13+ ] ;
14+
15+ export function shouldRefreshArtifactStoreForSettingsPatch ( body = { } ) {
16+ return ARTIFACT_STORE_SETTING_KEYS . some ( ( key ) =>
17+ Object . prototype . hasOwnProperty . call ( body , key ) ,
18+ ) ;
19+ }
20+
21+ export function getGithubAvatarApiUrl ( { username, githubApiUrl, githubProxy } ) {
22+ const githubApiBaseURL = getGithubGistBaseURL ( {
23+ githubApiUrl,
24+ githubProxy,
25+ } ) ;
26+
27+ return `${ githubApiBaseURL } /users/${ encodeURIComponent ( username ) } ` ;
28+ }
29+
830export default function register ( $app ) {
931 const settings = $ . read ( SETTINGS_KEY ) ;
1032 if ( ! settings ) $ . write ( { } , SETTINGS_KEY ) ;
@@ -19,7 +41,7 @@ async function getSettings(req, res) {
1941 $ . write ( settings , SETTINGS_KEY ) ;
2042 }
2143
22- if ( ! settings . avatarUrl ) await updateAvatar ( ) ;
44+ // await updateAvatar();
2345 if ( ! settings . artifactStore ) await updateArtifactStore ( ) ;
2446
2547 success ( res , settings ) ;
@@ -70,13 +92,8 @@ async function updateSettings(req, res) {
7092 }
7193 $ . write ( newSettings , SETTINGS_KEY ) ;
7294 clearLogSettingsCache ( ) ;
73- if (
74- req . body . githubUser ||
75- req . body . gistToken ||
76- req . body . githubProxy ||
77- req . body . defaultProxy
78- ) {
79- await updateAvatar ( ) ;
95+ if ( shouldRefreshArtifactStoreForSettingsPatch ( req . body ) ) {
96+ // await updateAvatar();
8097 await updateArtifactStore ( ) ;
8198 }
8299 success ( res , newSettings ) ;
@@ -95,7 +112,12 @@ async function updateSettings(req, res) {
95112
96113export async function updateAvatar ( ) {
97114 const settings = $ . read ( SETTINGS_KEY ) ;
98- const { githubUser : username , syncPlatform, githubProxy } = settings ;
115+ const {
116+ githubUser : username ,
117+ syncPlatform,
118+ githubProxy,
119+ githubApiUrl,
120+ } = settings ;
99121 if ( username ) {
100122 if ( syncPlatform === 'gitlab' ) {
101123 try {
@@ -126,11 +148,11 @@ export async function updateAvatar() {
126148 try {
127149 const data = await $ . http
128150 . get ( {
129- url : `${
130- githubProxy ? `${ githubProxy } /` : ''
131- } https://api.github.com/users/${ encodeURIComponent (
151+ url : getGithubAvatarApiUrl ( {
132152 username,
133- ) } `,
153+ githubApiUrl,
154+ githubProxy,
155+ } ) ,
134156 headers : {
135157 'User-Agent' :
136158 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.141 Safari/537.36' ,
0 commit comments