| 11 | const __dirname = path.dirname(__filename); |
| 12 | |
| 13 | class InspirationFetcher { |
| 14 | constructor() { |
| 15 | this.baseURL = 'https://api.github.com/repos/chokcoco/CSS-Inspiration'; |
| 16 | this.rawURL = 'https://raw.githubusercontent.com/chokcoco/CSS-Inspiration/master'; |
| 17 | this.dbPath = path.join(__dirname, '../data/icss.db'); |
| 18 | this.dataDir = path.join(__dirname, '../data'); |
| 19 | |
| 20 | // GitHub Token |
| 21 | this.githubToken = process.env.GITHUB_TOKEN; |
| 22 | if (!this.githubToken) { |
| 23 | console.warn('⚠️ No GITHUB_TOKEN found in environment variables. API rate limits will be restricted.'); |
| 24 | } |
| 25 | |
| 26 | // 确保数据目录存在 |
| 27 | if (!fs.existsSync(this.dataDir)) { |
| 28 | fs.mkdirSync(this.dataDir, { recursive: true }); |
| 29 | } |
| 30 | |
| 31 | // 初始化数据库连接 |
| 32 | this.db = new Database.Database(this.dbPath, (err) => { |
| 33 | if (err) { |
| 34 | console.error('❌ Error opening database:', err); |
| 35 | process.exit(1); |
| 36 | } |
| 37 | }); |
| 38 | |
| 39 | // CSS-Inspiration 分类映射 |
| 40 | this.categoryMapping = { |
| 41 | '3d': '3D 效果', |
| 42 | 'animation': '动画效果', |
| 43 | 'background': '背景效果', |
| 44 | 'blendmode': '混合模式', |
| 45 | 'border': '边框效果', |
| 46 | 'clippath': '裁剪路径', |
| 47 | 'cssdoodle': 'CSS-doodle', |
| 48 | 'filter': '滤镜效果', |
| 49 | 'layout': '布局技术', |
| 50 | 'others': '综合技巧', |
| 51 | 'pesudo': '伪类/伪元素', |
| 52 | 'shadow': '阴影效果', |
| 53 | 'svg': 'SVG 技术', |
| 54 | 'text': '文字效果' |
| 55 | }; |
| 56 | |
| 57 | this.initializeDatabase(); |
| 58 | } |
| 59 | |
| 60 | initializeDatabase() { |
| 61 | console.log('🔧 Initializing CSS-Inspiration tables...'); |
| 62 | |
| 63 | // CSS-Inspiration 项目表 |
| 64 | const createInspirationTableSQL = ` |
| 65 | CREATE TABLE IF NOT EXISTS css_inspiration ( |
| 66 | id INTEGER PRIMARY KEY, |
| 67 | category TEXT NOT NULL, |
| 68 | filename TEXT NOT NULL, |
| 69 | title TEXT NOT NULL, |
| 70 | description TEXT, |
nothing calls this directly
no outgoing calls
no test coverage detected