File size: 4,025 Bytes
25f22bf 3c29fcc 25f22bf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
import apiClient from './apiClient';
class SourceService {
/**
* Get all sources for the current user
* @returns {Promise} Promise that resolves to the sources data
*/
async getAll() {
try {
const response = await apiClient.get('/sources');
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.log('π° [Source] Retrieved sources:', response.data);
}
return response;
} catch (error) {
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.error('π° [Source] Get sources error:', error.response?.data || error.message);
}
throw error;
}
}
/**
* Analyze keyword frequency in sources
* @param {Object} keywordData - Keyword analysis data
* @param {string} keywordData.keyword - Keyword to analyze
* @param {string} [keywordData.date_range] - Date range for analysis ('daily', 'weekly', 'monthly'), defaults to 'monthly'
* @returns {Promise} Promise that resolves to the keyword analysis response
*/
async analyzeKeyword(keywordData) {
try {
const response = await apiClient.post('/sources/keyword-analysis', {
keyword: keywordData.keyword,
date_range: keywordData.date_range || 'monthly'
});
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.log('π° [Source] Keyword analysis result:', response.data);
}
return response;
} catch (error) {
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.error('π° [Source] Keyword analysis error:', error.response?.data || error.message);
}
throw error;
}
}
/**
* Analyze keyword frequency pattern in sources
* @param {Object} keywordData - Keyword pattern analysis data
* @param {string} keywordData.keyword - Keyword to analyze
* @returns {Promise} Promise that resolves to the keyword frequency pattern analysis response
*/
async analyzeKeywordPattern(keywordData) {
try {
const response = await apiClient.post('/sources/keyword-frequency-pattern', {
keyword: keywordData.keyword
});
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.log('π° [Source] Keyword frequency pattern analysis result:', response.data);
}
return response;
} catch (error) {
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.error('π° [Source] Keyword frequency pattern analysis error:', error.response?.data || error.message);
}
throw error;
}
}
/**
* Add a new source
* @param {Object} sourceData - Source data
* @param {string} sourceData.source - Source URL
* @returns {Promise} Promise that resolves to the add source response
*/
async create(sourceData) {
try {
const response = await apiClient.post('/sources', {
source: sourceData.source
});
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.log('π° [Source] Source created:', response.data);
}
return response;
} catch (error) {
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.error('π° [Source] Create source error:', error.response?.data || error.message);
}
throw error;
}
}
/**
* Delete a source
* @param {string} sourceId - Source ID
* @returns {Promise} Promise that resolves to the delete source response
*/
async delete(sourceId) {
try {
const response = await apiClient.delete(`/sources/${sourceId}`);
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.log('π° [Source] Source deleted:', response.data);
}
return response;
} catch (error) {
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.error('π° [Source] Delete source error:', error.response?.data || error.message);
}
throw error;
}
}
}
export default new SourceService(); |