|
|
|
@ -1,20 +1,9 @@
|
|
|
|
import { useCallback } from 'react';
|
|
|
|
import { useCallback } from 'react';
|
|
|
|
import { message } from 'antd';
|
|
|
|
import useConversationStore from '@/stores/ConversationStore';
|
|
|
|
|
|
|
|
|
|
|
|
const useShortUrlChange = () => {
|
|
|
|
const useShortUrlChange = () => {
|
|
|
|
const [messageApi, contextHolder] = message.useMessage();
|
|
|
|
const setGlobalNotify = useConversationStore((state) => state.setGlobalNotify);
|
|
|
|
const success = (content) => {
|
|
|
|
|
|
|
|
messageApi.open({
|
|
|
|
|
|
|
|
type: 'success',
|
|
|
|
|
|
|
|
content: content,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const error = (content) => {
|
|
|
|
|
|
|
|
messageApi.open({
|
|
|
|
|
|
|
|
type: 'error',
|
|
|
|
|
|
|
|
content: content,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const apiPrefix = {
|
|
|
|
const apiPrefix = {
|
|
|
|
"japanhighlights.com": "https://www.japanhighlights.com/index.php",
|
|
|
|
"japanhighlights.com": "https://www.japanhighlights.com/index.php",
|
|
|
|
"chinahighlights.com": "https://www.chinahighlights.com/guide-use.php",
|
|
|
|
"chinahighlights.com": "https://www.chinahighlights.com/guide-use.php",
|
|
|
|
@ -53,7 +42,12 @@ const useShortUrlChange = () => {
|
|
|
|
|
|
|
|
|
|
|
|
return { base64Url, extracted2 };
|
|
|
|
return { base64Url, extracted2 };
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
error('转换失败,请检查输入的URL是否正确');
|
|
|
|
setGlobalNotify([{
|
|
|
|
|
|
|
|
key: Date.now().toString(),
|
|
|
|
|
|
|
|
title: '错误',
|
|
|
|
|
|
|
|
content: '转换失败,请检查输入的URL是否正确',
|
|
|
|
|
|
|
|
type: 'error'
|
|
|
|
|
|
|
|
}]);
|
|
|
|
console.error('URL转换错误:', error);
|
|
|
|
console.error('URL转换错误:', error);
|
|
|
|
return { base64Url: '', extracted2: '' };
|
|
|
|
return { base64Url: '', extracted2: '' };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -61,7 +55,12 @@ const useShortUrlChange = () => {
|
|
|
|
|
|
|
|
|
|
|
|
const convertUrl = useCallback(async (longUrl) => {
|
|
|
|
const convertUrl = useCallback(async (longUrl) => {
|
|
|
|
if (!longUrl.trim()) {
|
|
|
|
if (!longUrl.trim()) {
|
|
|
|
error('不是有效的长链接');
|
|
|
|
setGlobalNotify([{
|
|
|
|
|
|
|
|
key: Date.now().toString(),
|
|
|
|
|
|
|
|
title: '错误',
|
|
|
|
|
|
|
|
content: '不是有效的长链接',
|
|
|
|
|
|
|
|
type: 'error'
|
|
|
|
|
|
|
|
}]);
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -74,19 +73,34 @@ const useShortUrlChange = () => {
|
|
|
|
const data = await fetchNowConversationsitems(base64Url, apiUrl);
|
|
|
|
const data = await fetchNowConversationsitems(base64Url, apiUrl);
|
|
|
|
if (data) {
|
|
|
|
if (data) {
|
|
|
|
const resultShortUrl = extracted1 + data.isl_link;
|
|
|
|
const resultShortUrl = extracted1 + data.isl_link;
|
|
|
|
success('转换成功!');
|
|
|
|
setGlobalNotify([{
|
|
|
|
|
|
|
|
key: Date.now().toString(),
|
|
|
|
|
|
|
|
title: '成功',
|
|
|
|
|
|
|
|
content: '转换成功!',
|
|
|
|
|
|
|
|
type: 'success'
|
|
|
|
|
|
|
|
}]);
|
|
|
|
return resultShortUrl;
|
|
|
|
return resultShortUrl;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
error('转换失败,请检查输入的URL是否正确');
|
|
|
|
setGlobalNotify([{
|
|
|
|
|
|
|
|
key: Date.now().toString(),
|
|
|
|
|
|
|
|
title: '错误',
|
|
|
|
|
|
|
|
content: '转换失败,请检查输入的URL是否正确',
|
|
|
|
|
|
|
|
type: 'error'
|
|
|
|
|
|
|
|
}]);
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
error('URL格式不正确,请输入完整的URL');
|
|
|
|
setGlobalNotify([{
|
|
|
|
|
|
|
|
key: Date.now().toString(),
|
|
|
|
|
|
|
|
title: '错误',
|
|
|
|
|
|
|
|
content: 'URL格式不正确,请输入完整的URL',
|
|
|
|
|
|
|
|
type: 'error'
|
|
|
|
|
|
|
|
}]);
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [messageApi]);
|
|
|
|
}, [setGlobalNotify]);
|
|
|
|
|
|
|
|
|
|
|
|
return { convertUrl, contextHolder };
|
|
|
|
return { convertUrl };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default useShortUrlChange;
|
|
|
|
export default useShortUrlChange;
|