Compare commits
5 Commits
36cbb6fda1
...
9dc01eeb46
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9dc01eeb46 | ||
|
|
811ad927f3 | ||
|
|
3033eb622f | ||
|
|
5edebd9d55 | ||
|
|
eba5c7e5c5 |
2
.env
2
.env
@@ -41,3 +41,5 @@ LOG_LEVEL=info
|
|||||||
|
|
||||||
# OpenAI API Key (用于 AI 推荐)
|
# OpenAI API Key (用于 AI 推荐)
|
||||||
ARK_API_KEY=a63d58b6-cf56-434b-8a42-5c781ba0822a
|
ARK_API_KEY=a63d58b6-cf56-434b-8a42-5c781ba0822a
|
||||||
|
|
||||||
|
SSH_PASSPHRASE=x
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@ build
|
|||||||
*.woff2
|
*.woff2
|
||||||
widget/looker/frontend/src/assets/fonts/OFL.txt
|
widget/looker/frontend/src/assets/fonts/OFL.txt
|
||||||
dist-electron
|
dist-electron
|
||||||
|
unpackage
|
||||||
@@ -54,6 +54,7 @@ import { ref } from 'vue'
|
|||||||
import api from '../utils/api'
|
import api from '../utils/api'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { Paperclip } from '@element-plus/icons-vue'
|
import { Paperclip } from '@element-plus/icons-vue'
|
||||||
|
import { formatDate } from '../utils/date.util'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
bids: any[]
|
bids: any[]
|
||||||
@@ -72,11 +73,6 @@ const selectedSource = ref('')
|
|||||||
const currentPage = ref(1)
|
const currentPage = ref(1)
|
||||||
const pageSize = ref(10)
|
const pageSize = ref(10)
|
||||||
|
|
||||||
const formatDate = (dateString: string) => {
|
|
||||||
if (!dateString) return '-'
|
|
||||||
return new Date(dateString).toLocaleDateString()
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSourceChange = () => {
|
const handleSourceChange = () => {
|
||||||
currentPage.value = 1
|
currentPage.value = 1
|
||||||
emit('fetch', currentPage.value, pageSize.value, selectedSource.value || undefined)
|
emit('fetch', currentPage.value, pageSize.value, selectedSource.value || undefined)
|
||||||
|
|||||||
@@ -16,12 +16,12 @@
|
|||||||
<el-table-column prop="count" label="本次获取数量" width="120" sortable />
|
<el-table-column prop="count" label="本次获取数量" width="120" sortable />
|
||||||
<el-table-column label="最近更新时间" width="180">
|
<el-table-column label="最近更新时间" width="180">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
{{ formatDate(row.latestUpdate) }}
|
{{ formatDateTime(row.latestUpdate) }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="最新工程时间" width="180">
|
<el-table-column label="最新工程时间" width="180">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
{{ formatDate(row.latestPublishDate) }}
|
{{ formatDateTime(row.latestPublishDate) }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="状态" width="100">
|
<el-table-column label="状态" width="100">
|
||||||
@@ -74,10 +74,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
|
||||||
import api from '../utils/api'
|
import api from '../utils/api'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { Refresh } from '@element-plus/icons-vue'
|
import { Refresh } from '@element-plus/icons-vue'
|
||||||
|
import { formatDateTime } from '../utils/date.util'
|
||||||
|
|
||||||
interface CrawlStat {
|
interface CrawlStat {
|
||||||
source: string
|
source: string
|
||||||
@@ -90,6 +91,7 @@ interface CrawlStat {
|
|||||||
const crawlStats = ref<CrawlStat[]>([])
|
const crawlStats = ref<CrawlStat[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const crawlingSources = ref<Set<string>>(new Set())
|
const crawlingSources = ref<Set<string>>(new Set())
|
||||||
|
let refreshTimer: number | null = null
|
||||||
|
|
||||||
const totalCount = computed(() => {
|
const totalCount = computed(() => {
|
||||||
return crawlStats.value.reduce((sum, item) => sum + item.count, 0)
|
return crawlStats.value.reduce((sum, item) => sum + item.count, 0)
|
||||||
@@ -103,18 +105,6 @@ const errorSources = computed(() => {
|
|||||||
return crawlStats.value.filter(item => item.error && item.error.trim()).length
|
return crawlStats.value.filter(item => item.error && item.error.trim()).length
|
||||||
})
|
})
|
||||||
|
|
||||||
const formatDate = (dateStr: string | null) => {
|
|
||||||
if (!dateStr) return '-'
|
|
||||||
const date = new Date(dateStr)
|
|
||||||
return date.toLocaleString('zh-CN', {
|
|
||||||
year: 'numeric',
|
|
||||||
month: '2-digit',
|
|
||||||
day: '2-digit',
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetchCrawlStats = async () => {
|
const fetchCrawlStats = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
@@ -140,7 +130,6 @@ const crawlSingleSource = async (sourceName: string) => {
|
|||||||
ElMessage.error(`${sourceName} 更新失败: ${res.data.error || '未知错误'}`)
|
ElMessage.error(`${sourceName} 更新失败: ${res.data.error || '未知错误'}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新统计数据
|
|
||||||
await fetchCrawlStats()
|
await fetchCrawlStats()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to crawl single source:', error)
|
console.error('Failed to crawl single source:', error)
|
||||||
@@ -150,8 +139,30 @@ const crawlSingleSource = async (sourceName: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const startAutoRefresh = () => {
|
||||||
|
if (refreshTimer !== null) {
|
||||||
|
clearInterval(refreshTimer)
|
||||||
|
}
|
||||||
|
// 取消自动刷新
|
||||||
|
// refreshTimer = window.setInterval(() => {
|
||||||
|
// fetchCrawlStats()
|
||||||
|
// }, REFRESH_INTERVAL)
|
||||||
|
}
|
||||||
|
|
||||||
|
const stopAutoRefresh = () => {
|
||||||
|
if (refreshTimer !== null) {
|
||||||
|
clearInterval(refreshTimer)
|
||||||
|
refreshTimer = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchCrawlStats()
|
fetchCrawlStats()
|
||||||
|
startAutoRefresh()
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
stopAutoRefresh()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ import api from '../utils/api'
|
|||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { Refresh, Paperclip } from '@element-plus/icons-vue'
|
import { Refresh, Paperclip } from '@element-plus/icons-vue'
|
||||||
import PinnedProject from './PinnedProject.vue'
|
import PinnedProject from './PinnedProject.vue'
|
||||||
|
import { formatDate } from '../utils/date.util'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
todayBids: any[]
|
todayBids: any[]
|
||||||
@@ -160,11 +161,6 @@ watch(dateRange, () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const formatDate = (dateString: string) => {
|
|
||||||
if (!dateString) return '-'
|
|
||||||
return new Date(dateString).toLocaleDateString()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 过滤 Today's Bids,只显示包含所选关键字的项目,并且在日期范围内
|
// 过滤 Today's Bids,只显示包含所选关键字的项目,并且在日期范围内
|
||||||
const filteredTodayBids = computed(() => {
|
const filteredTodayBids = computed(() => {
|
||||||
let result = props.todayBids
|
let result = props.todayBids
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
<el-table-column prop="source" label="来源" width="200" />
|
<el-table-column prop="source" label="来源" width="200" />
|
||||||
<el-table-column prop="publishDate" label="发布日期" width="180">
|
<el-table-column prop="publishDate" label="发布日期" width="180">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
{{ formatDate(scope.row.publishDate) }}
|
{{ formatSimpleDate(scope.row.publishDate) }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@@ -51,6 +51,7 @@ import { ref, onMounted } from 'vue'
|
|||||||
import api from '../utils/api'
|
import api from '../utils/api'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { Loading, InfoFilled, Paperclip } from '@element-plus/icons-vue'
|
import { Loading, InfoFilled, Paperclip } from '@element-plus/icons-vue'
|
||||||
|
import { formatSimpleDate } from '../utils/date.util'
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
pinChanged: [title: string]
|
pinChanged: [title: string]
|
||||||
@@ -88,16 +89,6 @@ const togglePin = async (item: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化日期,只显示年月日
|
|
||||||
const formatDate = (dateStr: string) => {
|
|
||||||
if (!dateStr) return ''
|
|
||||||
const date = new Date(dateStr)
|
|
||||||
const year = date.getFullYear()
|
|
||||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
|
||||||
const day = String(date.getDate()).padStart(2, '0')
|
|
||||||
return `${year}-${month}-${day}`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始化时加载置顶项目
|
// 初始化时加载置顶项目
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadPinnedBids()
|
loadPinnedBids()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import axios from 'axios'
|
|||||||
*/
|
*/
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
baseURL: 'http://localhost:3000', // 设置后端服务地址
|
baseURL: 'http://localhost:3000', // 设置后端服务地址
|
||||||
timeout: 10000, // 请求超时时间
|
timeout: 120000, // 请求超时时间(120秒)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 请求拦截器
|
// 请求拦截器
|
||||||
|
|||||||
58
frontend/src/utils/date.util.ts
Normal file
58
frontend/src/utils/date.util.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
* 日期格式化工具函数
|
||||||
|
* 统一处理东八区(Asia/Shanghai)时间显示
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化日期为 YYYY-MM-DD 格式
|
||||||
|
* @param dateStr 日期字符串或Date对象
|
||||||
|
* @returns 格式化后的日期字符串
|
||||||
|
*/
|
||||||
|
export function formatDate(dateStr: string | null | undefined): string {
|
||||||
|
if (!dateStr) return '-'
|
||||||
|
const date = new Date(dateStr)
|
||||||
|
if (isNaN(date.getTime())) return '-'
|
||||||
|
|
||||||
|
return date.toLocaleDateString('zh-CN', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
timeZone: 'Asia/Shanghai'
|
||||||
|
}).replace(/\//g, '-')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化日期时间为 YYYY-MM-DD HH:mm 格式
|
||||||
|
* @param dateStr 日期字符串或Date对象
|
||||||
|
* @returns 格式化后的日期时间字符串
|
||||||
|
*/
|
||||||
|
export function formatDateTime(dateStr: string | null | undefined): string {
|
||||||
|
if (!dateStr) return '-'
|
||||||
|
const date = new Date(dateStr)
|
||||||
|
if (isNaN(date.getTime())) return '-'
|
||||||
|
|
||||||
|
return date.toLocaleString('zh-CN', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
timeZone: 'Asia/Shanghai'
|
||||||
|
}).replace(/\//g, '-')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化日期为简洁的 YYYY-MM-DD 格式(用于置顶项目等)
|
||||||
|
* @param dateStr 日期字符串或Date对象
|
||||||
|
* @returns 格式化后的日期字符串
|
||||||
|
*/
|
||||||
|
export function formatSimpleDate(dateStr: string | null | undefined): string {
|
||||||
|
if (!dateStr) return ''
|
||||||
|
const date = new Date(dateStr)
|
||||||
|
if (isNaN(date.getTime())) return ''
|
||||||
|
|
||||||
|
const year = date.getFullYear()
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
|
const day = String(date.getDate()).padStart(2, '0')
|
||||||
|
return `${year}-${month}-${day}`
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
"start": "nest start",
|
"start": "nest start",
|
||||||
"start:dev": "nest start --watch",
|
"start:dev": "nest start --watch",
|
||||||
"start:debug": "nest start --debug --watch",
|
"start:debug": "nest start --debug --watch",
|
||||||
"start:prod": "node dist/main",
|
"start:prod": "node dist/main.js",
|
||||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test:watch": "jest --watch",
|
"test:watch": "jest --watch",
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
"update-source": "ts-node -r tsconfig-paths/register src/scripts/update-source.ts",
|
"update-source": "ts-node -r tsconfig-paths/register src/scripts/update-source.ts",
|
||||||
"ai-recommendations": "ts-node -r tsconfig-paths/register src/scripts/ai-recommendations.ts",
|
"ai-recommendations": "ts-node -r tsconfig-paths/register src/scripts/ai-recommendations.ts",
|
||||||
"sync": "ts-node -r tsconfig-paths/register src/scripts/sync.ts",
|
"sync": "ts-node -r tsconfig-paths/register src/scripts/sync.ts",
|
||||||
"deploy": "powershell -ExecutionPolicy Bypass -File src/scripts/deploy.ps1",
|
"deploy": "ts-node src/scripts/deploy.ts",
|
||||||
"electron:dev": "chcp 65001 >nul 2>&1 & npm run -prefix frontend build && npm run build && set NODE_ENV=development && electron ./app",
|
"electron:dev": "chcp 65001 >nul 2>&1 & npm run -prefix frontend build && npm run build && set NODE_ENV=development && electron ./app",
|
||||||
"electron:build": "npm run -prefix frontend build && npm run build && electron-builder --config ./app/electron-builder.json"
|
"electron:build": "npm run -prefix frontend build && npm run build && electron-builder --config ./app/electron-builder.json"
|
||||||
},
|
},
|
||||||
@@ -46,6 +46,7 @@
|
|||||||
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
|
"ssh2": "^1.17.0",
|
||||||
"typeorm": "^0.3.28",
|
"typeorm": "^0.3.28",
|
||||||
"winston": "^3.19.0",
|
"winston": "^3.19.0",
|
||||||
"winston-daily-rotate-file": "^5.0.0"
|
"winston-daily-rotate-file": "^5.0.0"
|
||||||
@@ -63,6 +64,8 @@
|
|||||||
"@types/jest": "^30.0.0",
|
"@types/jest": "^30.0.0",
|
||||||
"@types/node": "^22.10.7",
|
"@types/node": "^22.10.7",
|
||||||
"@types/responselike": "^1.0.3",
|
"@types/responselike": "^1.0.3",
|
||||||
|
"@types/ssh2": "^1.15.5",
|
||||||
|
"@types/ssh2-sftp-client": "^9.0.6",
|
||||||
"@types/supertest": "^6.0.2",
|
"@types/supertest": "^6.0.2",
|
||||||
"concurrently": "^9.2.1",
|
"concurrently": "^9.2.1",
|
||||||
"electron": "^39.2.7",
|
"electron": "^39.2.7",
|
||||||
@@ -74,6 +77,7 @@
|
|||||||
"jest": "^30.0.0",
|
"jest": "^30.0.0",
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.4.2",
|
||||||
"source-map-support": "^0.5.21",
|
"source-map-support": "^0.5.21",
|
||||||
|
"ssh2-sftp-client": "^12.0.1",
|
||||||
"supertest": "^7.0.0",
|
"supertest": "^7.0.0",
|
||||||
"ts-jest": "^29.2.5",
|
"ts-jest": "^29.2.5",
|
||||||
"ts-loader": "^9.5.2",
|
"ts-loader": "^9.5.2",
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export const PromptString: string = `先给我说你统计了多少个项目。我只对辽宁、山东、江苏、浙江、福建、广东、广西、海南、河北这些地方的海上风电、海上光伏、漂浮式光伏、滩涂光伏、滩涂风电、渔光互补项目感兴趣。从我提供的这些工程里面找到我感兴趣的工程,无论如何至少推荐10个工程。如果没有推荐的,也要给出思考过程。`;
|
export const PromptString: string = `先给我说你统计了多少个项目。我只对辽宁、山东、江苏、浙江、福建、广东、广西、海南、河北这些地方的海上风电、海上光伏、漂浮式光伏、滩涂光伏、滩涂风电、渔光互补、风光互补项目感兴趣。从我提供的这些工程里面找到我感兴趣的工程,无论如何至少推荐10个工程。如果没有推荐的,也要给出思考过程。`;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { ScheduleModule } from '@nestjs/schedule';
|
import { ScheduleModule } from '@nestjs/schedule';
|
||||||
import { ServeStaticModule } from '@nestjs/serve-static';
|
import { ServeStaticModule } from '@nestjs/serve-static';
|
||||||
@@ -9,6 +9,7 @@ import { KeywordsModule } from './keywords/keywords.module';
|
|||||||
import { CrawlerModule } from './crawler/crawler.module';
|
import { CrawlerModule } from './crawler/crawler.module';
|
||||||
import { TasksModule } from './schedule/schedule.module';
|
import { TasksModule } from './schedule/schedule.module';
|
||||||
import { LoggerModule } from './common/logger/logger.module';
|
import { LoggerModule } from './common/logger/logger.module';
|
||||||
|
import { LoggingMiddleware } from './common/logger/logging.middleware';
|
||||||
import { AiModule } from './ai/ai.module';
|
import { AiModule } from './ai/ai.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
@@ -28,4 +29,8 @@ import { AiModule } from './ai/ai.module';
|
|||||||
AiModule,
|
AiModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule implements NestModule {
|
||||||
|
configure(consumer: MiddlewareConsumer) {
|
||||||
|
consumer.apply(LoggingMiddleware).forRoutes('*');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ import { InjectRepository } from '@nestjs/typeorm';
|
|||||||
import { Repository, LessThan } from 'typeorm';
|
import { Repository, LessThan } from 'typeorm';
|
||||||
import { BidItem } from '../entities/bid-item.entity';
|
import { BidItem } from '../entities/bid-item.entity';
|
||||||
import { CrawlInfoAdd } from '../../crawler/entities/crawl-info-add.entity';
|
import { CrawlInfoAdd } from '../../crawler/entities/crawl-info-add.entity';
|
||||||
|
import {
|
||||||
|
getDaysAgo,
|
||||||
|
setStartOfDay,
|
||||||
|
setEndOfDay,
|
||||||
|
} from '../../common/utils/timezone.util';
|
||||||
|
|
||||||
interface FindAllQuery {
|
interface FindAllQuery {
|
||||||
page?: number;
|
page?: number;
|
||||||
@@ -73,8 +78,7 @@ export class BidsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async cleanOldData() {
|
async cleanOldData() {
|
||||||
const thirtyDaysAgo = new Date();
|
const thirtyDaysAgo = getDaysAgo(30);
|
||||||
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
|
|
||||||
return this.bidRepository.delete({
|
return this.bidRepository.delete({
|
||||||
createdAt: LessThan(thirtyDaysAgo),
|
createdAt: LessThan(thirtyDaysAgo),
|
||||||
});
|
});
|
||||||
@@ -91,9 +95,7 @@ export class BidsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getRecentBids() {
|
async getRecentBids() {
|
||||||
const thirtyDaysAgo = new Date();
|
const thirtyDaysAgo = setStartOfDay(getDaysAgo(30));
|
||||||
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
|
|
||||||
thirtyDaysAgo.setHours(0, 0, 0, 0);
|
|
||||||
|
|
||||||
return this.bidRepository
|
return this.bidRepository
|
||||||
.createQueryBuilder('bid')
|
.createQueryBuilder('bid')
|
||||||
@@ -118,14 +120,12 @@ export class BidsService {
|
|||||||
const qb = this.bidRepository.createQueryBuilder('bid');
|
const qb = this.bidRepository.createQueryBuilder('bid');
|
||||||
|
|
||||||
if (startDate) {
|
if (startDate) {
|
||||||
const start = new Date(startDate);
|
const start = setStartOfDay(new Date(startDate));
|
||||||
start.setHours(0, 0, 0, 0);
|
|
||||||
qb.andWhere('bid.publishDate >= :startDate', { startDate: start });
|
qb.andWhere('bid.publishDate >= :startDate', { startDate: start });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endDate) {
|
if (endDate) {
|
||||||
const end = new Date(endDate);
|
const end = setEndOfDay(new Date(endDate));
|
||||||
end.setHours(23, 59, 59, 999);
|
|
||||||
qb.andWhere('bid.publishDate <= :endDate', { endDate: end });
|
qb.andWhere('bid.publishDate <= :endDate', { endDate: end });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ export class BidsService {
|
|||||||
return results.map((item) => ({
|
return results.map((item) => ({
|
||||||
source: String(item.source),
|
source: String(item.source),
|
||||||
count: Number(item.count),
|
count: Number(item.count),
|
||||||
latestUpdate: item.latestUpdate,
|
latestUpdate: item.latestUpdate ? item.latestUpdate + 'Z' : null,
|
||||||
latestPublishDate: item.latestPublishDate,
|
latestPublishDate: item.latestPublishDate,
|
||||||
// 确保 error 字段正确处理:null 或空字符串都转换为 null,非空字符串保留
|
// 确保 error 字段正确处理:null 或空字符串都转换为 null,非空字符串保留
|
||||||
error:
|
error:
|
||||||
|
|||||||
29
src/common/logger/logging.middleware.ts
Normal file
29
src/common/logger/logging.middleware.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { Injectable, NestMiddleware } from '@nestjs/common';
|
||||||
|
import { Request, Response, NextFunction } from 'express';
|
||||||
|
import { CustomLogger } from './logger.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class LoggingMiddleware implements NestMiddleware {
|
||||||
|
constructor(private readonly logger: CustomLogger) {
|
||||||
|
this.logger.setContext('HTTP');
|
||||||
|
}
|
||||||
|
|
||||||
|
use(req: Request, res: Response, next: NextFunction) {
|
||||||
|
const { method, originalUrl, ip } = req;
|
||||||
|
const userAgent = req.get('user-agent') || '';
|
||||||
|
const startTime = Date.now();
|
||||||
|
|
||||||
|
// 收到请求时立即输出
|
||||||
|
this.logger.debug(`--> ${method} ${originalUrl} - ${ip} - ${userAgent}`);
|
||||||
|
|
||||||
|
res.on('finish', () => {
|
||||||
|
const { statusCode } = res;
|
||||||
|
const duration = Date.now() - startTime;
|
||||||
|
this.logger.debug(
|
||||||
|
`<-- ${method} ${originalUrl} ${statusCode} - ${duration}ms`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -76,6 +76,10 @@ const errorLogTransport = new DailyRotateFile({
|
|||||||
export const winstonLogger = winston.createLogger({
|
export const winstonLogger = winston.createLogger({
|
||||||
level: process.env.LOG_LEVEL || 'info',
|
level: process.env.LOG_LEVEL || 'info',
|
||||||
format: logFormat,
|
format: logFormat,
|
||||||
transports: [consoleTransport, appLogTransport as any, errorLogTransport as any],
|
transports: [
|
||||||
|
consoleTransport,
|
||||||
|
appLogTransport as any,
|
||||||
|
errorLogTransport as any,
|
||||||
|
],
|
||||||
exitOnError: false,
|
exitOnError: false,
|
||||||
});
|
});
|
||||||
|
|||||||
98
src/common/utils/timezone.util.ts
Normal file
98
src/common/utils/timezone.util.ts
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
/**
|
||||||
|
* 时区工具函数
|
||||||
|
* 统一处理东八区(Asia/Shanghai)时间相关的操作
|
||||||
|
*/
|
||||||
|
|
||||||
|
const TIMEZONE_OFFSET = 8 * 60 * 60 * 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前时间的东八区Date对象
|
||||||
|
* @returns Date 当前时间的东八区表示
|
||||||
|
*/
|
||||||
|
export function getCurrentDateInTimezone(): Date {
|
||||||
|
const now = new Date();
|
||||||
|
const utc = now.getTime() + now.getTimezoneOffset() * 60 * 1000;
|
||||||
|
return new Date(utc + TIMEZONE_OFFSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将任意Date对象转换为东八区时间
|
||||||
|
* @param date 原始Date对象
|
||||||
|
* @returns Date 转换后的东八区时间
|
||||||
|
*/
|
||||||
|
export function convertToTimezone(date: Date): Date {
|
||||||
|
const utc = date.getTime() + date.getTimezoneOffset() * 60 * 1000;
|
||||||
|
return new Date(utc + TIMEZONE_OFFSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化日期为 YYYY-MM-DD 格式
|
||||||
|
* @param date Date对象
|
||||||
|
* @returns 格式化后的日期字符串
|
||||||
|
*/
|
||||||
|
export function formatDate(date: Date): string {
|
||||||
|
const timezoneDate = convertToTimezone(date);
|
||||||
|
const year = timezoneDate.getFullYear();
|
||||||
|
const month = String(timezoneDate.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(timezoneDate.getDate()).padStart(2, '0');
|
||||||
|
return `${year}-${month}-${day}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化日期时间为 YYYY-MM-DD HH:mm:ss 格式
|
||||||
|
* @param date Date对象
|
||||||
|
* @returns 格式化后的日期时间字符串
|
||||||
|
*/
|
||||||
|
export function formatDateTime(date: Date): string {
|
||||||
|
const timezoneDate = convertToTimezone(date);
|
||||||
|
const year = timezoneDate.getFullYear();
|
||||||
|
const month = String(timezoneDate.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(timezoneDate.getDate()).padStart(2, '0');
|
||||||
|
const hours = String(timezoneDate.getHours()).padStart(2, '0');
|
||||||
|
const minutes = String(timezoneDate.getMinutes()).padStart(2, '0');
|
||||||
|
const seconds = String(timezoneDate.getSeconds()).padStart(2, '0');
|
||||||
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置时间为当天的开始时间 (00:00:00.000)
|
||||||
|
* @param date Date对象
|
||||||
|
* @returns 设置后的Date对象
|
||||||
|
*/
|
||||||
|
export function setStartOfDay(date: Date): Date {
|
||||||
|
const timezoneDate = convertToTimezone(date);
|
||||||
|
timezoneDate.setHours(0, 0, 0, 0);
|
||||||
|
return timezoneDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置时间为当天的结束时间 (23:59:59.999)
|
||||||
|
* @param date Date对象
|
||||||
|
* @returns 设置后的Date对象
|
||||||
|
*/
|
||||||
|
export function setEndOfDay(date: Date): Date {
|
||||||
|
const timezoneDate = convertToTimezone(date);
|
||||||
|
timezoneDate.setHours(23, 59, 59, 999);
|
||||||
|
return timezoneDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定天数前的日期
|
||||||
|
* @param days 天数
|
||||||
|
* @returns 指定天数前的Date对象
|
||||||
|
*/
|
||||||
|
export function getDaysAgo(days: number): Date {
|
||||||
|
const date = getCurrentDateInTimezone();
|
||||||
|
date.setDate(date.getDate() - days);
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析日期字符串为东八区Date对象
|
||||||
|
* @param dateStr 日期字符串 (支持 YYYY-MM-DD 或 YYYY-MM-DD HH:mm:ss 格式)
|
||||||
|
* @returns 解析后的Date对象
|
||||||
|
*/
|
||||||
|
export function parseDateString(dateStr: string): Date {
|
||||||
|
const date = new Date(dateStr);
|
||||||
|
return convertToTimezone(date);
|
||||||
|
}
|
||||||
@@ -139,7 +139,10 @@ export const CdtCrawler = {
|
|||||||
logger.log(`Navigating to ${this.url}...`);
|
logger.log(`Navigating to ${this.url}...`);
|
||||||
await delayRetry(
|
await delayRetry(
|
||||||
async () => {
|
async () => {
|
||||||
await page.goto(this.url, { waitUntil: 'networkidle2', timeout: 60000 });
|
await page.goto(this.url, {
|
||||||
|
waitUntil: 'networkidle2',
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
5000,
|
5000,
|
||||||
|
|||||||
@@ -142,7 +142,10 @@ export const CeicCrawler = {
|
|||||||
logger.log(`Navigating to ${this.url}...`);
|
logger.log(`Navigating to ${this.url}...`);
|
||||||
await delayRetry(
|
await delayRetry(
|
||||||
async () => {
|
async () => {
|
||||||
await page.goto(this.url, { waitUntil: 'networkidle2', timeout: 60000 });
|
await page.goto(this.url, {
|
||||||
|
waitUntil: 'networkidle2',
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
5000,
|
5000,
|
||||||
|
|||||||
@@ -148,7 +148,10 @@ export const CgnpcCrawler = {
|
|||||||
logger.log(`Navigating to ${this.url}...`);
|
logger.log(`Navigating to ${this.url}...`);
|
||||||
await delayRetry(
|
await delayRetry(
|
||||||
async () => {
|
async () => {
|
||||||
await page.goto(this.url, { waitUntil: 'networkidle2', timeout: 60000 });
|
await page.goto(this.url, {
|
||||||
|
waitUntil: 'networkidle2',
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
5000,
|
5000,
|
||||||
|
|||||||
@@ -1,10 +1,50 @@
|
|||||||
import * as puppeteer from 'puppeteer';
|
import * as puppeteer from 'puppeteer';
|
||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
|
|
||||||
|
async function simulateHumanMouseMovement(page: puppeteer.Page) {
|
||||||
|
const viewport = page.viewport();
|
||||||
|
if (!viewport) return;
|
||||||
|
|
||||||
|
const movements = 5 + Math.floor(Math.random() * 5);
|
||||||
|
|
||||||
|
for (let i = 0; i < movements; i++) {
|
||||||
|
const x = Math.floor(Math.random() * viewport.width);
|
||||||
|
const y = Math.floor(Math.random() * viewport.height);
|
||||||
|
|
||||||
|
await page.mouse.move(x, y, {
|
||||||
|
steps: 10 + Math.floor(Math.random() * 20),
|
||||||
|
});
|
||||||
|
|
||||||
|
await new Promise((r) => setTimeout(r, 100 + Math.random() * 400));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function simulateHumanScrolling(page: puppeteer.Page) {
|
||||||
|
const scrollCount = 3 + Math.floor(Math.random() * 5);
|
||||||
|
|
||||||
|
for (let i = 0; i < scrollCount; i++) {
|
||||||
|
const scrollDistance = 100 + Math.floor(Math.random() * 400);
|
||||||
|
|
||||||
|
await page.evaluate((distance) => {
|
||||||
|
window.scrollBy({
|
||||||
|
top: distance,
|
||||||
|
behavior: 'smooth',
|
||||||
|
});
|
||||||
|
}, scrollDistance);
|
||||||
|
|
||||||
|
await new Promise((r) => setTimeout(r, 500 + Math.random() * 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
await page.evaluate(() => {
|
||||||
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||||
|
});
|
||||||
|
await new Promise((r) => setTimeout(r, 1000));
|
||||||
|
}
|
||||||
|
|
||||||
export interface ChdtpResult {
|
export interface ChdtpResult {
|
||||||
title: string;
|
title: string;
|
||||||
publishDate: Date;
|
publishDate: Date;
|
||||||
url: string; // Necessary for system uniqueness
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ChdtpCrawlerType {
|
interface ChdtpCrawlerType {
|
||||||
@@ -94,13 +134,22 @@ export const ChdtpCrawler = {
|
|||||||
logger.log(`Navigating to ${this.url}...`);
|
logger.log(`Navigating to ${this.url}...`);
|
||||||
await delayRetry(
|
await delayRetry(
|
||||||
async () => {
|
async () => {
|
||||||
await page.goto(this.url, { waitUntil: 'networkidle2', timeout: 60000 });
|
await page.goto(this.url, {
|
||||||
|
waitUntil: 'networkidle2',
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
5000,
|
5000,
|
||||||
logger,
|
logger,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
logger.log('Simulating human mouse movements...');
|
||||||
|
await simulateHumanMouseMovement(page);
|
||||||
|
|
||||||
|
logger.log('Simulating human scrolling...');
|
||||||
|
await simulateHumanScrolling(page);
|
||||||
|
|
||||||
while (currentPage <= maxPages) {
|
while (currentPage <= maxPages) {
|
||||||
const content = await page.content();
|
const content = await page.content();
|
||||||
const pageResults = this.extract(content);
|
const pageResults = this.extract(content);
|
||||||
@@ -115,6 +164,12 @@ export const ChdtpCrawler = {
|
|||||||
`Extracted ${pageResults.length} items from page ${currentPage}`,
|
`Extracted ${pageResults.length} items from page ${currentPage}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
logger.log('Simulating human mouse movements before pagination...');
|
||||||
|
await simulateHumanMouseMovement(page);
|
||||||
|
|
||||||
|
logger.log('Simulating human scrolling before pagination...');
|
||||||
|
await simulateHumanScrolling(page);
|
||||||
|
|
||||||
// Find the "Next Page" button
|
// Find the "Next Page" button
|
||||||
// Using partial match for src to be robust against path variations
|
// Using partial match for src to be robust against path variations
|
||||||
const nextButtonSelector = 'input[type="image"][src*="page-next.png"]';
|
const nextButtonSelector = 'input[type="image"][src*="page-next.png"]';
|
||||||
@@ -125,9 +180,6 @@ export const ChdtpCrawler = {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optional: Check if the button is disabled (though image inputs usually aren't "disabled" in the same way)
|
|
||||||
// For this specific site, we'll try to click.
|
|
||||||
|
|
||||||
logger.log(`Navigating to page ${currentPage + 1}...`);
|
logger.log(`Navigating to page ${currentPage + 1}...`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -149,6 +201,12 @@ export const ChdtpCrawler = {
|
|||||||
|
|
||||||
currentPage++;
|
currentPage++;
|
||||||
|
|
||||||
|
logger.log('Simulating human mouse movements after pagination...');
|
||||||
|
await simulateHumanMouseMovement(page);
|
||||||
|
|
||||||
|
logger.log('Simulating human scrolling after pagination...');
|
||||||
|
await simulateHumanScrolling(page);
|
||||||
|
|
||||||
// Random delay between pages
|
// Random delay between pages
|
||||||
const delay = Math.floor(Math.random() * (3000 - 1000 + 1)) + 1000;
|
const delay = Math.floor(Math.random() * (3000 - 1000 + 1)) + 1000;
|
||||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||||
|
|||||||
@@ -148,7 +148,10 @@ export const CnncecpCrawler = {
|
|||||||
logger.log(`Navigating to ${this.url}...`);
|
logger.log(`Navigating to ${this.url}...`);
|
||||||
await delayRetry(
|
await delayRetry(
|
||||||
async () => {
|
async () => {
|
||||||
await page.goto(this.url, { waitUntil: 'networkidle2', timeout: 60000 });
|
await page.goto(this.url, {
|
||||||
|
waitUntil: 'networkidle2',
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
5000,
|
5000,
|
||||||
|
|||||||
@@ -148,7 +148,10 @@ export const CnoocCrawler = {
|
|||||||
logger.log(`Navigating to ${this.url}...`);
|
logger.log(`Navigating to ${this.url}...`);
|
||||||
await delayRetry(
|
await delayRetry(
|
||||||
async () => {
|
async () => {
|
||||||
await page.goto(this.url, { waitUntil: 'networkidle2', timeout: 60000 });
|
await page.goto(this.url, {
|
||||||
|
waitUntil: 'networkidle2',
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
5000,
|
5000,
|
||||||
|
|||||||
@@ -148,7 +148,10 @@ export const EpsCrawler = {
|
|||||||
logger.log(`Navigating to ${this.url}...`);
|
logger.log(`Navigating to ${this.url}...`);
|
||||||
await delayRetry(
|
await delayRetry(
|
||||||
async () => {
|
async () => {
|
||||||
await page.goto(this.url, { waitUntil: 'networkidle2', timeout: 60000 });
|
await page.goto(this.url, {
|
||||||
|
waitUntil: 'networkidle2',
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
5000,
|
5000,
|
||||||
|
|||||||
@@ -148,7 +148,10 @@ export const PowerbeijingCrawler = {
|
|||||||
logger.log(`Navigating to ${this.url}...`);
|
logger.log(`Navigating to ${this.url}...`);
|
||||||
await delayRetry(
|
await delayRetry(
|
||||||
async () => {
|
async () => {
|
||||||
await page.goto(this.url, { waitUntil: 'networkidle2', timeout: 60000 });
|
await page.goto(this.url, {
|
||||||
|
waitUntil: 'networkidle2',
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
5000,
|
5000,
|
||||||
|
|||||||
@@ -148,7 +148,10 @@ export const SdiccCrawler = {
|
|||||||
logger.log(`Navigating to ${this.url}...`);
|
logger.log(`Navigating to ${this.url}...`);
|
||||||
await delayRetry(
|
await delayRetry(
|
||||||
async () => {
|
async () => {
|
||||||
await page.goto(this.url, { waitUntil: 'networkidle2', timeout: 60000 });
|
await page.goto(this.url, {
|
||||||
|
waitUntil: 'networkidle2',
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
5000,
|
5000,
|
||||||
|
|||||||
@@ -142,7 +142,10 @@ export const SzecpCrawler = {
|
|||||||
logger.log(`Navigating to ${this.url}...`);
|
logger.log(`Navigating to ${this.url}...`);
|
||||||
await delayRetry(
|
await delayRetry(
|
||||||
async () => {
|
async () => {
|
||||||
await page.goto(this.url, { waitUntil: 'networkidle2', timeout: 60000 });
|
await page.goto(this.url, {
|
||||||
|
waitUntil: 'networkidle2',
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
5000,
|
5000,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
|||||||
database: configService.get<string>('DATABASE_NAME', 'bidding'),
|
database: configService.get<string>('DATABASE_NAME', 'bidding'),
|
||||||
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
|
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
|
timezone: '+08:00',
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'dotenv/config';
|
||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
import { CustomLogger } from './common/logger/logger.service';
|
import { CustomLogger } from './common/logger/logger.service';
|
||||||
|
|||||||
149
src/scripts/deploy.ts
Normal file
149
src/scripts/deploy.ts
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
/**
|
||||||
|
* Deploy script - Upload files to remote server using SSH2
|
||||||
|
* 使用 ssh2-sftp-client 避免每次输入密钥密码
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import * as path from 'path';
|
||||||
|
import SftpClient from 'ssh2-sftp-client';
|
||||||
|
import * as dotenv from 'dotenv';
|
||||||
|
|
||||||
|
// 加载 .env 文件
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
// Configuration
|
||||||
|
const config = {
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: 1122,
|
||||||
|
username: 'cubie',
|
||||||
|
privateKey: fs.readFileSync('d:\\163'),
|
||||||
|
passphrase: process.env.SSH_PASSPHRASE || '',
|
||||||
|
};
|
||||||
|
|
||||||
|
const destinations = {
|
||||||
|
server: '/home/cubie/down/document/bidding/publish/server',
|
||||||
|
frontend: '/home/cubie/down/document/bidding/publish/frontend',
|
||||||
|
src: '/home/cubie/down/document/bidding/',
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
async function uploadDirectory(
|
||||||
|
sftp: SftpClient,
|
||||||
|
localPath: string,
|
||||||
|
remotePath: string,
|
||||||
|
): Promise<void> {
|
||||||
|
const startTime = Date.now();
|
||||||
|
console.log(`\n[上传] ${localPath} -> ${remotePath}`);
|
||||||
|
|
||||||
|
// 检查本地目录
|
||||||
|
if (!fs.existsSync(localPath)) {
|
||||||
|
throw new Error(`本地目录不存在: ${localPath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 统计文件数量
|
||||||
|
const countFiles = (dir: string): number => {
|
||||||
|
let count = 0;
|
||||||
|
const items = fs.readdirSync(dir);
|
||||||
|
for (const item of items) {
|
||||||
|
const fullPath = path.join(dir, item);
|
||||||
|
if (fs.statSync(fullPath).isDirectory()) {
|
||||||
|
count += countFiles(fullPath);
|
||||||
|
} else {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
};
|
||||||
|
|
||||||
|
const fileCount = countFiles(localPath);
|
||||||
|
console.log(` 文件数量: ${fileCount}`);
|
||||||
|
|
||||||
|
await sftp.uploadDir(localPath, remotePath);
|
||||||
|
|
||||||
|
const duration = ((Date.now() - startTime) / 1000).toFixed(2);
|
||||||
|
console.log(` 完成! 耗时: ${duration}s`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deploy(): Promise<void> {
|
||||||
|
// 检查必要目录
|
||||||
|
const requiredDirs = ['dist', 'frontend', 'src'];
|
||||||
|
for (const dir of requiredDirs) {
|
||||||
|
if (!fs.existsSync(dir)) {
|
||||||
|
console.error(`${dir} 目录不存在`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查私钥文件
|
||||||
|
if (!fs.existsSync('d:\\163')) {
|
||||||
|
console.error('私钥文件不存在: d:\\163');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.passphrase) {
|
||||||
|
console.error('请在 .env 文件中设置 SSH_PASSPHRASE');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const sftp = new SftpClient();
|
||||||
|
|
||||||
|
// 添加详细日志
|
||||||
|
sftp.on('upload', (info) => {
|
||||||
|
console.log(` 已上传: ${info.source}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log('开始部署...');
|
||||||
|
console.log(`远程服务器: ${config.host}:${config.port}`);
|
||||||
|
console.log(`用户名: ${config.username}`);
|
||||||
|
console.log(`私钥文件: d:\\163`);
|
||||||
|
console.log('正在连接...');
|
||||||
|
|
||||||
|
await sftp.connect({
|
||||||
|
...config,
|
||||||
|
keepaliveInterval: 5000, // 每5秒发送keepalive
|
||||||
|
keepaliveCountMax: 10,
|
||||||
|
readyTimeout: 60000, // 60秒连接超时
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('连接成功!');
|
||||||
|
|
||||||
|
// 上传 dist 目录内容到 server 目录
|
||||||
|
await uploadDirectory(sftp, 'dist', destinations.server);
|
||||||
|
|
||||||
|
// 上传 frontend/dist 到 frontend 目录
|
||||||
|
await uploadDirectory(
|
||||||
|
sftp,
|
||||||
|
path.join('frontend', 'dist'),
|
||||||
|
destinations.frontend,
|
||||||
|
);
|
||||||
|
|
||||||
|
// 上传 src 目录
|
||||||
|
await uploadDirectory(sftp, 'src', destinations.src + 'src');
|
||||||
|
|
||||||
|
// 上传 package.json
|
||||||
|
console.log('\n[上传] package.json -> ' + destinations.src + 'package.json');
|
||||||
|
await sftp.put('package.json', destinations.src + 'package.json');
|
||||||
|
console.log(' 已上传: package.json');
|
||||||
|
|
||||||
|
console.log('\n========================================');
|
||||||
|
console.log('部署完成!');
|
||||||
|
console.log('========================================');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('\n========================================');
|
||||||
|
console.error('部署失败!');
|
||||||
|
console.error('========================================');
|
||||||
|
console.error('错误信息:', err instanceof Error ? err.message : err);
|
||||||
|
if (err instanceof Error && err.stack) {
|
||||||
|
console.error('\n堆栈信息:');
|
||||||
|
console.error(err.stack);
|
||||||
|
}
|
||||||
|
process.exit(1);
|
||||||
|
} finally {
|
||||||
|
console.log('\n断开连接...');
|
||||||
|
await sftp.end();
|
||||||
|
console.log('连接已关闭');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deploy();
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
{
|
{
|
||||||
"name": "bidding-looker",
|
"name" : "bidding-looker",
|
||||||
"appid": "__UNI__BIDDING_LOOKER",
|
"appid" : "__UNI__1D1820F",
|
||||||
"description": "投标项目查看器",
|
"description" : "投标项目查看器",
|
||||||
"versionName": "1.0.0",
|
"versionName" : "1.0.0",
|
||||||
"versionCode": "100",
|
"versionCode" : "100",
|
||||||
"transformPx": false,
|
"transformPx" : false,
|
||||||
"app-plus": {
|
"app-plus" : {
|
||||||
"usingComponents": true,
|
"usingComponents" : true,
|
||||||
"nvueStyleCompiler": "uni-app",
|
"nvueStyleCompiler" : "uni-app",
|
||||||
"compilerVersion": 3,
|
"compilerVersion" : 3,
|
||||||
"splashscreen": {
|
"splashscreen" : {
|
||||||
"alwaysShowBeforeRender": true,
|
"alwaysShowBeforeRender" : true,
|
||||||
"waiting": true,
|
"waiting" : true,
|
||||||
"autoclose": true,
|
"autoclose" : true,
|
||||||
"delay": 0
|
"delay" : 0
|
||||||
},
|
},
|
||||||
"modules": {},
|
"modules" : {},
|
||||||
"distribute": {
|
"distribute" : {
|
||||||
"android": {
|
"android" : {
|
||||||
"permissions": [
|
"permissions" : [
|
||||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||||
@@ -35,39 +35,41 @@
|
|||||||
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"ios": {},
|
"ios" : {
|
||||||
"sdkConfigs": {}
|
"dSYMs" : false
|
||||||
|
},
|
||||||
|
"sdkConfigs" : {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"quickapp": {},
|
"quickapp" : {},
|
||||||
"mp-weixin": {
|
"mp-weixin" : {
|
||||||
"appid": "",
|
"appid" : "",
|
||||||
"setting": {
|
"setting" : {
|
||||||
"urlCheck": false
|
"urlCheck" : false
|
||||||
},
|
},
|
||||||
"usingComponents": true
|
"usingComponents" : true
|
||||||
},
|
},
|
||||||
"mp-alipay": {
|
"mp-alipay" : {
|
||||||
"usingComponents": true
|
"usingComponents" : true
|
||||||
},
|
},
|
||||||
"mp-baidu": {
|
"mp-baidu" : {
|
||||||
"usingComponents": true
|
"usingComponents" : true
|
||||||
},
|
},
|
||||||
"mp-toutiao": {
|
"mp-toutiao" : {
|
||||||
"usingComponents": true
|
"usingComponents" : true
|
||||||
},
|
},
|
||||||
"uniStatistics": {
|
"uniStatistics" : {
|
||||||
"enable": false
|
"enable" : false
|
||||||
},
|
},
|
||||||
"vueVersion": "3",
|
"vueVersion" : "3",
|
||||||
"h5": {
|
"h5" : {
|
||||||
"router": {
|
"router" : {
|
||||||
"mode": "hash",
|
"mode" : "hash",
|
||||||
"base": "/"
|
"base" : "/"
|
||||||
},
|
},
|
||||||
"devServer": {
|
"devServer" : {
|
||||||
"port": 8080,
|
"port" : 8080,
|
||||||
"disableHostCheck": true
|
"disableHostCheck" : true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user