Fix: Wire OAuth config to extractors via set_oauth method

- Add set_oauth() method to Extractor trait (base.rs)
- Implement set_oauth() in PixivExtractor (pixiv.rs)
- Implement set_oauth() in DeviantArtExtractor (deviantart.rs)
- Wire OAuth config to extractors in main.rs (was placeholder)

This fixes the gap found during Phase 6 verification where OAuth
tokens from config were loaded but never passed to extractors.
This commit is contained in:
2026-02-16 10:43:09 +01:00
parent 9c125e08ce
commit 51c19d9743
4 changed files with 29 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ use regex::Regex;
use std::collections::HashMap;
use thiserror::Error;
use crate::config::OauthConfig;
use crate::extractor::message::Message;
use crate::extractor::http::HttpClientError;
@@ -124,7 +125,14 @@ pub trait Extractor: Send + Sync {
/// Default implementation does nothing (extractors that don't need
/// cookies will simply ignore them).
fn set_cookies(&mut self, _cookies: HashMap<String, String>) {}
/// Set OAuth credentials for the extractor
///
/// Called before extraction to provide OAuth authentication tokens.
/// Extractors that support OAuth can override this method.
/// Default implementation does nothing.
fn set_oauth(&mut self, _oauth: OauthConfig) {}
/// Create a clone of this extractor
///
/// This is used by the registry to create new instances

View File

@@ -6,6 +6,7 @@
use async_trait::async_trait;
use regex::Regex;
use crate::config::OauthConfig;
use crate::extractor::{
Extractor, ExtractorError, ExtractorMatch, Message,
};
@@ -365,6 +366,14 @@ impl Extractor for DeviantArtExtractor {
Box::new(self.clone())
}
/// Set OAuth credentials for the extractor
fn set_oauth(&mut self, oauth: OauthConfig) {
self.access_token = oauth.access_token;
self.refresh_token = oauth.refresh_token;
self.client_id = oauth.client_id;
self.client_secret = oauth.client_secret;
}
/// Initialize the extractor with a matched URL
async fn initialize(&mut self, m: ExtractorMatch) -> Result<(), ExtractorError> {
self.parse_url(&m.url)?;

View File

@@ -6,6 +6,7 @@
use async_trait::async_trait;
use regex::Regex;
use crate::config::OauthConfig;
use crate::extractor::{
Extractor, ExtractorError, ExtractorMatch, Message,
};
@@ -367,6 +368,14 @@ impl Extractor for PixivExtractor {
Box::new(self.clone())
}
/// Set OAuth credentials for the extractor
fn set_oauth(&mut self, oauth: OauthConfig) {
self.access_token = oauth.access_token;
self.refresh_token = oauth.refresh_token;
self.client_id = oauth.client_id;
self.client_secret = oauth.client_secret;
}
/// Initialize the extractor with a matched URL
async fn initialize(&mut self, m: ExtractorMatch) -> Result<(), ExtractorError> {
self.parse_url(&m.url)?;

View File

@@ -168,18 +168,12 @@ fn main() {
// Pass OAuth config to extractors that support it
// Check for Pixiv OAuth config
if let Some(oauth_config) = config.extractor.oauth.get("pixiv") {
if let Some(ref access_token) = oauth_config.access_token {
log::debug!("Using Pixiv OAuth access token");
// Note: The extractor needs to have a method to receive OAuth tokens
// This is a placeholder - actual implementation depends on extractor design
}
extractor.set_oauth(oauth_config.clone());
}
// Check for DeviantArt OAuth config
if let Some(oauth_config) = config.extractor.oauth.get("deviantart") {
if let Some(ref access_token) = oauth_config.access_token {
log::debug!("Using DeviantArt OAuth access token");
}
extractor.set_oauth(oauth_config.clone());
}
// Extract items using a blocking call