Lin / frontend /src /services /sourceService.js
Zelyanoth's picture
feat: add keyword analysis functionality and enhance content service
3c29fcc
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();