initial
This commit is contained in:
@@ -58,17 +58,17 @@ from datetime import timedelta
|
||||
cache_time = timedelta(days=3)
|
||||
|
||||
@app.get("/search/")
|
||||
@cache_result(cache_time)
|
||||
# @cache_result(cache_time)
|
||||
def search_site(search_query: str, page: int = 1):
|
||||
try:
|
||||
page = client.search_site(search_query=search_query, page=page)
|
||||
results = [{"album_id": album_id, "title": title} for album_id, title in page]
|
||||
results = [{"album_id": album_id, "name": title} for album_id, title in page]
|
||||
return results
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
@app.get("/album/{album_id}/")
|
||||
@cache_result(cache_time)
|
||||
# @cache_result(cache_time)
|
||||
def get_album_details(album_id: int):
|
||||
try:
|
||||
page = client.search_site(search_query=str(album_id))
|
||||
@@ -77,6 +77,92 @@ def get_album_details(album_id: int):
|
||||
image_urls = []
|
||||
nums = []
|
||||
# 遍历每个章节
|
||||
|
||||
|
||||
for photo in album:
|
||||
# 章节实体类
|
||||
photo_detail = client.get_photo_detail(photo.photo_id, False)
|
||||
|
||||
# 遍历每个图片
|
||||
for image in photo_detail:
|
||||
# 图片实体类
|
||||
image_urls.append(image.img_url)
|
||||
nums.append(JmImageTool.get_num_by_url(image.scramble_id, image.img_url))
|
||||
|
||||
return {
|
||||
"album_id": album.album_id,
|
||||
"scramble_id": album.scramble_id,
|
||||
"name": album.name,
|
||||
"page_count": album.page_count,
|
||||
"pub_date": album.pub_date,
|
||||
"update_date": album.update_date,
|
||||
"likes": album.likes,
|
||||
"views": album.views,
|
||||
"comment_count": album.comment_count,
|
||||
"works": album.works,
|
||||
"actors": album.actors,
|
||||
"authors": album.authors,
|
||||
"tags": album.tags,
|
||||
"related_list": album.related_list,
|
||||
"episode_list": album.episode_list,
|
||||
"image_urls": image_urls,
|
||||
"nums": nums
|
||||
}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
|
||||
@app.get("/album/{album_id}/debug")
|
||||
# @cache_result(cache_time)
|
||||
def get_album_details(album_id: int):
|
||||
try:
|
||||
page = client.search_site(search_query=str(album_id))
|
||||
album = page.single_album
|
||||
|
||||
# 输出调试信息到控制台
|
||||
import json as json_module
|
||||
|
||||
# 创建简单的序列化函数,避免复杂对象导致的问题
|
||||
def simple_serialize(obj):
|
||||
if hasattr(obj, '__dict__'):
|
||||
result = {}
|
||||
for key, value in obj.__dict__.items():
|
||||
try:
|
||||
# 尝试直接序列化
|
||||
json_module.dumps(value)
|
||||
result[key] = value
|
||||
except:
|
||||
# 如果不能序列化,转换为字符串
|
||||
result[key] = str(value)
|
||||
return result
|
||||
else:
|
||||
return str(obj)
|
||||
|
||||
# 输出page和album的调试信息到控制台
|
||||
print("=" * 50)
|
||||
print("DEBUG: Page object")
|
||||
print("=" * 50)
|
||||
try:
|
||||
print(json_module.dumps(simple_serialize(page), indent=2, ensure_ascii=False))
|
||||
except Exception as e:
|
||||
print(f"无法序列化page对象: {e}")
|
||||
print(f"Page类型: {type(page)}")
|
||||
print(f"Page属性: {[attr for attr in dir(page) if not attr.startswith('_')]}")
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("DEBUG: Album object")
|
||||
print("=" * 50)
|
||||
try:
|
||||
print(json_module.dumps(simple_serialize(album), indent=2, ensure_ascii=False))
|
||||
except Exception as e:
|
||||
print(f"无法序列化album对象: {e}")
|
||||
print(f"Album类型: {type(album)}")
|
||||
print(f"Album属性: {[attr for attr in dir(album) if not attr.startswith('_')]}")
|
||||
|
||||
# 存储所有图片的URL
|
||||
image_urls = []
|
||||
nums = []
|
||||
# 遍历每个章节
|
||||
for photo in album:
|
||||
# 章节实体类
|
||||
photo_detail = client.get_photo_detail(photo.photo_id, False)
|
||||
@@ -110,57 +196,8 @@ def get_album_details(album_id: int):
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
|
||||
@app.get("/album/{album_id}/chapters/")
|
||||
@cache_result(cache_time)
|
||||
def get_album_chapters_paginated(album_id: int, page: int = 1, per_page: int = 5):
|
||||
"""
|
||||
分页获取专辑章节列表
|
||||
:param album_id: 专辑ID
|
||||
:param page: 页码(从1开始)
|
||||
:param per_page: 每页章节数
|
||||
"""
|
||||
try:
|
||||
page_result = client.search_site(search_query=str(album_id))
|
||||
album = page_result.single_album
|
||||
|
||||
# 计算分页信息
|
||||
total_chapters = len(album.photos)
|
||||
total_pages = (total_chapters + per_page - 1) // per_page # 向上取整
|
||||
|
||||
if page < 1 or page > total_pages:
|
||||
raise HTTPException(status_code=404, detail="Page out of range")
|
||||
|
||||
# 计算当前页的章节范围
|
||||
start_index = (page - 1) * per_page
|
||||
end_index = min(start_index + per_page, total_chapters)
|
||||
|
||||
# 获取当前页的章节信息
|
||||
chapters = []
|
||||
for i in range(start_index, end_index):
|
||||
photo = album.photos[i]
|
||||
chapters.append({
|
||||
"chapter_index": i,
|
||||
"chapter_id": photo.photo_id,
|
||||
"title": photo.name,
|
||||
"page_count": photo.page_count,
|
||||
"pub_date": photo.pub_date
|
||||
})
|
||||
|
||||
return {
|
||||
"album_id": album.album_id,
|
||||
"album_name": album.name,
|
||||
"current_page": page,
|
||||
"per_page": per_page,
|
||||
"total_chapters": total_chapters,
|
||||
"total_pages": total_pages,
|
||||
"chapters": chapters
|
||||
}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
|
||||
@app.get("/fast/{album_id}/")
|
||||
# @cache_result(cache_time)
|
||||
@cache_result(cache_time)
|
||||
def get_album_details(album_id: int):
|
||||
try:
|
||||
page = client.search_site(search_query=str(album_id))
|
||||
|
||||
@@ -7,24 +7,24 @@
|
||||
|
||||
<!-- 基础 Meta 标签 -->
|
||||
<title>Powered by Reisa</title>
|
||||
<meta name="description" content="Union 官网" />
|
||||
<meta name="keywords" content="ReisaPage,Vue,Vite,ServerMonitoring,FindMaimai,Maimai,Reisa,Spasol" />
|
||||
<meta name="description" content="ReiJM" />
|
||||
<meta name="keywords" content="ReiJM,Vue,Vite,ServerMonitoring ,Maimai" />
|
||||
<meta name="author" content="Reisa" />
|
||||
|
||||
<!-- Open Graph / Facebook -->
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:url" content="https://www.godserver.cn" />
|
||||
<meta property="og:title" content="Reisa Spasol" />
|
||||
<meta property="og:description" content="Union 网站" />
|
||||
<meta property="og:title" content="ReiJM" />
|
||||
<meta property="og:description" content="ReiJM 网站" />
|
||||
<meta property="og:image" content="/src/assets/logo.png" />
|
||||
<meta property="og:locale" content="zh_CN" />
|
||||
<meta property="og:site_name" content="Reisa Spasol" />
|
||||
<meta property="og:site_name" content="ReiJM" />
|
||||
|
||||
<!-- Twitter -->
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:site" content="@Spaso1" />
|
||||
<meta name="twitter:title" content="Reisa Spasol" />
|
||||
<meta name="twitter:description" content="Reisa 个人网站" />
|
||||
<meta name="twitter:site" content="@ReiJM" />
|
||||
<meta name="twitter:title" content="ReiJM" />
|
||||
<meta name="twitter:description" content="ReiJM" />
|
||||
<meta name="twitter:image" content="/src/assets/logo.png" />
|
||||
|
||||
<!-- 主题色 -->
|
||||
@@ -35,7 +35,7 @@
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Organization",
|
||||
"name": " Powered by Reisa",
|
||||
"name": " Powered by ReiJM",
|
||||
"url": "https://www.godserver.cn",
|
||||
"logo": "/src/assets/logo.png",
|
||||
"sameAs": ["https://github.com/Spaso1", "https://twitter.com/Spaso1"]
|
||||
|
||||
@@ -85,7 +85,7 @@ const toggleMenu = () => {
|
||||
<span
|
||||
class="text-xl md:text-2xl font-bold bg-gradient-to-r from-blue-500 via-purple-500 to-pink-500 bg-clip-text text-transparent bg-[length:200%_auto] hover:animate-gradient whitespace-nowrap"
|
||||
>
|
||||
Union
|
||||
ReiJM
|
||||
</span>
|
||||
</router-link>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const siteConfig = {
|
||||
// 基本信息
|
||||
name: "Powered by Reisa", // 作者名称
|
||||
name: "Re", // 作者名称
|
||||
title: "FindMaimaiDX开发者 学生", // 职位头衔
|
||||
siteName: "ReisaSpasol | MaimaiDX", // 网站标题
|
||||
siteDescription:
|
||||
|
||||
@@ -1,17 +1,581 @@
|
||||
<script setup lang="ts">import { useRouter } from 'vue-router'
|
||||
<!-- HomeView.vue -->
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, reactive } from 'vue'
|
||||
import axios from 'axios'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
interface Album {
|
||||
album_id: string
|
||||
name: string
|
||||
image_urls: string[]
|
||||
nums: number[]
|
||||
authors?: string[]
|
||||
tags?: string[]
|
||||
}
|
||||
|
||||
const router = useRouter()
|
||||
const albums = ref<Album[]>([])
|
||||
const loading = ref(false)
|
||||
const page = ref(1)
|
||||
const hasMore = ref(true)
|
||||
const observer = ref<IntersectionObserver | null>(null)
|
||||
|
||||
// 搜索相关
|
||||
const searchKeyword = ref('')
|
||||
const searchResults = ref<Album[]>([])
|
||||
const searching = ref(false)
|
||||
const showSearchResults = ref(false)
|
||||
|
||||
// 存储已解码的封面图片
|
||||
const coverImages = reactive<Record<string, string>>({})
|
||||
// 记录已处理的专辑,避免重复处理
|
||||
const processedAlbums = new Set<string>()
|
||||
// 记录已解码完成的专辑,用于控制显示
|
||||
const decodedAlbums = reactive<Record<string, boolean>>({})
|
||||
|
||||
// 获取推荐漫画
|
||||
const fetchRecommendedManga = async () => {
|
||||
if (loading.value || !hasMore.value) return
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const response = await axios.get(`/api/manga/weeking?page=${page.value}`)
|
||||
const newAlbums: Album[] = response.data
|
||||
|
||||
if (newAlbums.length === 0) {
|
||||
hasMore.value = false
|
||||
return
|
||||
}
|
||||
|
||||
// 添加新专辑到列表
|
||||
albums.value = [...albums.value, ...newAlbums]
|
||||
|
||||
// 为新专辑解码封面
|
||||
newAlbums.forEach(album => {
|
||||
if (!processedAlbums.has(album.album_id)) {
|
||||
decodeAndCacheCover(album)
|
||||
processedAlbums.add(album.album_id)
|
||||
}
|
||||
})
|
||||
|
||||
page.value++
|
||||
} catch (error) {
|
||||
console.error('获取推荐漫画失败:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 解码图片
|
||||
const decodeImage = (imgSrc: HTMLImageElement, num: number): string => {
|
||||
if (num === 0) {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = imgSrc.width
|
||||
canvas.height = imgSrc.height
|
||||
const ctx = canvas.getContext('2d')
|
||||
ctx?.drawImage(imgSrc, 0, 0)
|
||||
return canvas.toDataURL()
|
||||
}
|
||||
|
||||
const w = imgSrc.width
|
||||
const h = imgSrc.height
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = w
|
||||
canvas.height = h
|
||||
const ctx = canvas.getContext('2d')!
|
||||
|
||||
const over = h % num
|
||||
|
||||
for (let i = 0; i < num; i++) {
|
||||
let move = Math.floor(h / num)
|
||||
let ySrc = h - move * (i + 1) - over
|
||||
let yDst = move * i
|
||||
|
||||
if (i === 0) {
|
||||
move += over
|
||||
} else {
|
||||
yDst += over
|
||||
}
|
||||
|
||||
const srcRect = { x: 0, y: ySrc, width: w, height: move }
|
||||
const dstRect = { x: 0, y: yDst, width: w, height: move }
|
||||
|
||||
const tempCanvas = document.createElement('canvas')
|
||||
tempCanvas.width = w
|
||||
tempCanvas.height = move
|
||||
const tempCtx = tempCanvas.getContext('2d')!
|
||||
tempCtx.drawImage(
|
||||
imgSrc,
|
||||
srcRect.x,
|
||||
srcRect.y,
|
||||
srcRect.width,
|
||||
srcRect.height,
|
||||
0,
|
||||
0,
|
||||
srcRect.width,
|
||||
srcRect.height
|
||||
)
|
||||
|
||||
ctx.drawImage(
|
||||
tempCanvas,
|
||||
0,
|
||||
0,
|
||||
tempCanvas.width,
|
||||
tempCanvas.height,
|
||||
dstRect.x,
|
||||
dstRect.y,
|
||||
dstRect.width,
|
||||
dstRect.height
|
||||
)
|
||||
}
|
||||
|
||||
return canvas.toDataURL()
|
||||
}
|
||||
|
||||
// 解码并缓存封面图片
|
||||
const decodeAndCacheCover = (album: Album) => {
|
||||
// 如果没有图片URL,返回默认图片
|
||||
if (!album.image_urls || album.image_urls.length === 0) {
|
||||
decodedAlbums[album.album_id] = true
|
||||
return
|
||||
}
|
||||
|
||||
const img = new Image()
|
||||
img.crossOrigin = 'anonymous'
|
||||
img.src = album.image_urls[0]
|
||||
|
||||
img.onload = () => {
|
||||
// 使用第一张图片的解码参数
|
||||
const num = album.nums && album.nums.length > 0 ? album.nums[0] : 0
|
||||
if (num !== 0) {
|
||||
const decodedImage = decodeImage(img, num)
|
||||
coverImages[album.album_id] = decodedImage
|
||||
} else {
|
||||
coverImages[album.album_id] = img.src
|
||||
}
|
||||
// 标记解码完成
|
||||
decodedAlbums[album.album_id] = true
|
||||
}
|
||||
|
||||
img.onerror = () => {
|
||||
// 加载失败时使用原始URL
|
||||
coverImages[album.album_id] = album.image_urls[0]
|
||||
// 标记解码完成(即使失败也标记完成)
|
||||
decodedAlbums[album.album_id] = true
|
||||
}
|
||||
}
|
||||
|
||||
// 获取封面图片URL
|
||||
const getCoverImageUrl = (album: Album): string => {
|
||||
// 如果已经解码过,直接返回解码后的图片
|
||||
if (coverImages[album.album_id]) {
|
||||
return coverImages[album.album_id]
|
||||
}
|
||||
|
||||
// 如果有原始URL,返回原始URL
|
||||
if (album.image_urls && album.image_urls.length > 0) {
|
||||
return album.image_urls[0]
|
||||
}
|
||||
|
||||
// 否则返回空
|
||||
return ''
|
||||
}
|
||||
|
||||
// 检查专辑封面是否已解码完成
|
||||
const isAlbumDecoded = (album: Album): boolean => {
|
||||
return decodedAlbums[album.album_id] === true
|
||||
}
|
||||
|
||||
// 跳转到漫画详情页
|
||||
const goToManga = (albumId: string) => {
|
||||
router.push(`/manga/${albumId}`)
|
||||
}
|
||||
|
||||
// 搜索功能
|
||||
const searchManga = async () => {
|
||||
if (!searchKeyword.value.trim()) {
|
||||
searchResults.value = []
|
||||
showSearchResults.value = false
|
||||
return
|
||||
}
|
||||
|
||||
searching.value = true
|
||||
showSearchResults.value = true
|
||||
try {
|
||||
const response = await axios.get(`/api/manga/search`, {
|
||||
params: {
|
||||
keyword: searchKeyword.value,
|
||||
page: 1,
|
||||
type: 0
|
||||
}
|
||||
})
|
||||
searchResults.value = response.data
|
||||
|
||||
// 为搜索结果解码封面
|
||||
searchResults.value.forEach(album => {
|
||||
if (!processedAlbums.has(album.album_id)) {
|
||||
decodeAndCacheCover(album)
|
||||
processedAlbums.add(album.album_id)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('搜索漫画失败:', error)
|
||||
} finally {
|
||||
searching.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理回车键搜索
|
||||
const handleSearchKey = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Enter') {
|
||||
searchManga()
|
||||
}
|
||||
}
|
||||
|
||||
// 清空搜索
|
||||
const clearSearch = () => {
|
||||
searchKeyword.value = ''
|
||||
searchResults.value = []
|
||||
showSearchResults.value = false
|
||||
}
|
||||
|
||||
// 设置无限滚动观察器
|
||||
const setupInfiniteScroll = () => {
|
||||
observer.value = new IntersectionObserver((entries) => {
|
||||
const target = entries[0]
|
||||
if (target.isIntersecting && !loading.value && hasMore.value && !showSearchResults.value) {
|
||||
fetchRecommendedManga()
|
||||
}
|
||||
}, {
|
||||
rootMargin: '100px' // 提前100px触发加载
|
||||
})
|
||||
|
||||
const loadMoreTrigger = document.getElementById('load-more-trigger')
|
||||
if (loadMoreTrigger && observer.value) {
|
||||
observer.value.observe(loadMoreTrigger)
|
||||
}
|
||||
}
|
||||
|
||||
// 组件挂载时初始化
|
||||
onMounted(() => {
|
||||
fetchRecommendedManga().then(() => {
|
||||
// 等待DOM更新后设置无限滚动
|
||||
setTimeout(setupInfiniteScroll, 0)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="home-view">
|
||||
<div class="header">
|
||||
<h1>{{ showSearchResults ? `搜索结果: ${searchKeyword}` : '推荐漫画' }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="manga-grid">
|
||||
<div
|
||||
v-for="album in (showSearchResults ? searchResults : albums)"
|
||||
:key="album.album_id"
|
||||
class="manga-card"
|
||||
@click="goToManga(album.album_id)"
|
||||
>
|
||||
<div class="manga-cover">
|
||||
<!-- 只有解码完成后才显示图片 -->
|
||||
<img
|
||||
v-if="isAlbumDecoded(album) && getCoverImageUrl(album)"
|
||||
:src="getCoverImageUrl(album)"
|
||||
:alt="album.name"
|
||||
@error="($event) => {
|
||||
const target = $event.target as HTMLImageElement;
|
||||
if (album.image_urls && album.image_urls.length > 0) {
|
||||
target.src = album.image_urls[0];
|
||||
}
|
||||
}"
|
||||
/>
|
||||
<div v-else class="loading-cover">加载中...</div>
|
||||
</div>
|
||||
<div class="manga-info">
|
||||
<h3 class="manga-title">{{ album.name }}</h3>
|
||||
<div v-if="album.authors && album.authors.length" class="manga-authors">
|
||||
作者: {{ album.authors.join(', ') }}
|
||||
</div>
|
||||
<div v-if="album.tags && album.tags.length" class="manga-tags">
|
||||
<span
|
||||
v-for="(tag, index) in album.tags.slice(0, 3)"
|
||||
:key="index"
|
||||
class="tag"
|
||||
>
|
||||
{{ tag }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="!showSearchResults"
|
||||
id="load-more-trigger"
|
||||
class="load-more-trigger"
|
||||
>
|
||||
<div v-if="loading" class="loading">加载中...</div>
|
||||
<div v-else-if="!hasMore" class="no-more">没有更多了</div>
|
||||
</div>
|
||||
|
||||
<!-- 搜索框 -->
|
||||
<div class="search-container">
|
||||
<div class="search-box">
|
||||
<div class="search-input-container">
|
||||
<input
|
||||
v-model="searchKeyword"
|
||||
type="text"
|
||||
placeholder="输入漫画名称或作者..."
|
||||
class="search-input"
|
||||
@keyup="handleSearchKey"
|
||||
/>
|
||||
<button
|
||||
v-if="searchKeyword"
|
||||
class="clear-button"
|
||||
@click="clearSearch"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
<div v-if="searching" class="search-loading">搜索中...</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.home-view {
|
||||
background-color: black;
|
||||
background-color: #000;
|
||||
color: white;
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
padding-bottom: 100px; /* 为底部搜索框留出空间 */
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 28px;
|
||||
margin: 0;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.manga-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.manga-card {
|
||||
background-color: #1a1a1a;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.manga-card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.manga-cover {
|
||||
width: 100%;
|
||||
aspect-ratio: 2/3;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.manga-cover img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.loading-cover, .no-cover {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: #333;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.manga-info {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.manga-title {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
margin: 0 0 8px 0;
|
||||
color: #fff;
|
||||
line-height: 1.3;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.manga-authors {
|
||||
font-size: 13px;
|
||||
color: #aaa;
|
||||
margin-bottom: 8px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.manga-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.tag {
|
||||
background-color: #333;
|
||||
color: #ccc;
|
||||
font-size: 10px;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.load-more-trigger {
|
||||
text-align: center;
|
||||
padding: 30px 0;
|
||||
}
|
||||
|
||||
.loading {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.no-more {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* 搜索框样式 */
|
||||
.search-container {
|
||||
position: fixed;
|
||||
bottom: 20mm;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
z-index: 1000;
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
background-color: rgba(26, 26, 26, 0.95);
|
||||
border-radius: 12px;
|
||||
padding: 15px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.search-input-container {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
padding: 12px 40px 12px 15px;
|
||||
border-radius: 8px;
|
||||
border: 2px solid #444;
|
||||
background-color: #222;
|
||||
color: white;
|
||||
font-size: 16px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
border-color: #1e90ff;
|
||||
}
|
||||
|
||||
.clear-button {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
background: none;
|
||||
border: none;
|
||||
color: #999;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.clear-button:hover {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.search-loading {
|
||||
position: absolute;
|
||||
right: 40px;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* 平板适配 */
|
||||
@media (max-width: 768px) {
|
||||
.home-view {
|
||||
padding: 15px;
|
||||
padding-bottom: 100px;
|
||||
}
|
||||
|
||||
.manga-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
/* 手机适配 */
|
||||
@media (max-width: 480px) {
|
||||
.home-view {
|
||||
padding: 10px;
|
||||
padding-bottom: 100px;
|
||||
}
|
||||
|
||||
.manga-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.manga-info {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.manga-title {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.manga-authors {
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.tag {
|
||||
font-size: 9px;
|
||||
padding: 1px 4px;
|
||||
}
|
||||
|
||||
.search-container {
|
||||
width: 95%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
import { ref, onMounted, onUnmounted, computed, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import axios from 'axios'
|
||||
import router from "@/router";
|
||||
|
||||
const route = useRoute()
|
||||
const token = localStorage.getItem('token')
|
||||
|
||||
// 漫画专辑数据
|
||||
interface AlbumData {
|
||||
@@ -25,7 +27,7 @@ const albumInfo = ref<Omit<AlbumData, 'image_urls' | 'nums'> | null>(null)
|
||||
const showMenu = ref(false)
|
||||
const isFullscreen = ref(false)
|
||||
const showDrawer = ref(false)
|
||||
const currentImageIndex = ref(0) // 当前显示的图片索引
|
||||
let currentImageIndex = ref(0) // 当前显示的图片索引
|
||||
const imageStates = ref<Array<{ scale: number; translateX: number; translateY: number }>>([])
|
||||
const loading = ref(true)
|
||||
const canvasImages = ref<string[]>([]) // 解码后的图片
|
||||
@@ -35,6 +37,20 @@ const abortLoading = ref(false) // 取消加载标志
|
||||
const shouldHideHeader = computed(() => {
|
||||
return route.meta?.hideHeader === true
|
||||
})
|
||||
// 在现有代码中添加新的函数
|
||||
const reportReadManga = async (mangaId: string, index: number) => {
|
||||
try {
|
||||
await axios.post('/api/manga/read', {}, {
|
||||
headers: {
|
||||
Token: token || '',
|
||||
mangaId: mangaId,
|
||||
index: index.toString()
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('上报阅读进度失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 计算当前页码信息
|
||||
const currentPageInfo = computed(() => {
|
||||
@@ -51,10 +67,12 @@ const fetchAlbum = async (id: string) => {
|
||||
|
||||
try {
|
||||
loading.value = true
|
||||
console.log('发送请求到:', `/api/manga/read?mangaId=${id}`)
|
||||
const response = await axios.get(`/api/manga/read?mangaId=${id}`, {
|
||||
maxRedirects: 5,
|
||||
validateStatus: (status) => status < 500,
|
||||
headers: {
|
||||
Token: `${token}`
|
||||
}
|
||||
})
|
||||
console.log('收到响应:', response)
|
||||
|
||||
@@ -96,6 +114,9 @@ const fetchAlbum = async (id: string) => {
|
||||
} else {
|
||||
loading.value = false
|
||||
}
|
||||
scrollToImage(data.readIndex)
|
||||
currentImageIndex.value = data.readIndex
|
||||
console.log(currentImageIndex.value)
|
||||
} catch (error) {
|
||||
console.error('加载专辑失败', error)
|
||||
loading.value = false
|
||||
@@ -286,7 +307,7 @@ const handleTouchMove = (index: number, event: TouchEvent) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 处理滚轮缩放(仅鼠标滚轮)
|
||||
// 处理滚轮缩放(以鼠标位置为中心点缩放)
|
||||
const handleWheel = (index: number, event: WheelEvent) => {
|
||||
// 确保是鼠标滚轮事件而不是触摸板手势
|
||||
if (Math.abs(event.deltaX) > Math.abs(event.deltaY) * 2) {
|
||||
@@ -297,15 +318,50 @@ const handleWheel = (index: number, event: WheelEvent) => {
|
||||
event.preventDefault()
|
||||
const currentState = imageStates.value[index]
|
||||
|
||||
// 获取图片元素
|
||||
const imgElement = document.getElementById(`image-${index}`)?.querySelector('.manga-image')
|
||||
if (!imgElement) return
|
||||
|
||||
// 计算鼠标在图片中的相对位置
|
||||
const rect = imgElement.getBoundingClientRect()
|
||||
const mouseX = event.clientX - rect.left
|
||||
const mouseY = event.clientY - rect.top
|
||||
|
||||
// 计算当前鼠标位置相对于图片中心的偏移(减小移动幅度)
|
||||
const centerX = rect.width / 2.7
|
||||
const centerY = rect.height / 2.5
|
||||
const offsetX = (mouseX - centerX) * 0.4 // 减少移动幅度
|
||||
const offsetY = (mouseY - centerY) * 0.4 // 减少移动幅度
|
||||
|
||||
if (event.deltaY < 0) {
|
||||
// 向上滚动放大
|
||||
if (currentState.scale < 3) {
|
||||
currentState.scale *= 1.1
|
||||
const newScale = currentState.scale * 1.1
|
||||
const scaleRatio = newScale / currentState.scale
|
||||
|
||||
// 以鼠标位置为中心进行缩放(减小位移)
|
||||
const newTranslateX = currentState.translateX - offsetX * (scaleRatio - 1)
|
||||
const newTranslateY = currentState.translateY - offsetY * (scaleRatio - 1)
|
||||
|
||||
currentState.scale = newScale
|
||||
currentState.translateX = newTranslateX
|
||||
currentState.translateY = newTranslateY
|
||||
}
|
||||
} else {
|
||||
// 向下滚动缩小
|
||||
if (currentState.scale > 1) {
|
||||
currentState.scale /= 1.1
|
||||
const newScale = currentState.scale / 1.1
|
||||
const scaleRatio = newScale / currentState.scale
|
||||
|
||||
// 以鼠标位置为中心进行缩放(减小位移)
|
||||
const newTranslateX = currentState.translateX - offsetX * (scaleRatio - 1)
|
||||
const newTranslateY = currentState.translateY - offsetY * (scaleRatio - 1)
|
||||
|
||||
currentState.scale = newScale
|
||||
currentState.translateX = newTranslateX
|
||||
currentState.translateY = newTranslateY
|
||||
|
||||
// 如果缩放到原始大小,重置位置
|
||||
if (currentState.scale <= 1) {
|
||||
currentState.scale = 1
|
||||
currentState.translateX = 0
|
||||
@@ -381,6 +437,10 @@ const handleScroll = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const back = () => {
|
||||
router.push('/')
|
||||
}
|
||||
|
||||
// 使用节流优化滚动处理
|
||||
const throttledHandleScroll = throttle(handleScroll, 100)
|
||||
|
||||
@@ -416,9 +476,31 @@ watch(
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
let refreshInterval: number | null = null;
|
||||
|
||||
// 新增:刷新token的函数
|
||||
const refreshToken = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) return;
|
||||
|
||||
const response = await axios.post('/api/user/ref', {
|
||||
data: token,
|
||||
timestamp: Date.now()
|
||||
}, {
|
||||
headers: {
|
||||
'Token' : token,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Refresh token failed:', error);
|
||||
}
|
||||
};
|
||||
// 组件挂载时添加事件监听器
|
||||
onMounted(() => {
|
||||
refreshInterval = window.setInterval(refreshToken, 30000);
|
||||
|
||||
window.addEventListener('keydown', handleKeydown)
|
||||
// 直接监听 manga-reader 元素的滚动事件,而不是 manga-content
|
||||
const mangaReader = document.querySelector('.manga-reader')
|
||||
@@ -429,6 +511,16 @@ onMounted(() => {
|
||||
// 初始化当前图片索引
|
||||
handleScroll()
|
||||
})
|
||||
// 替换现有的 watch 监听器
|
||||
watch([currentImageIndex, loading, mangaImages], ([newIndex, isLoading, images]) => {
|
||||
// 只有在非加载状态且索引有效时才发送请求
|
||||
if (albumInfo.value && !isLoading && newIndex >= 0 &&
|
||||
newIndex < images.length) {
|
||||
reportReadManga(albumInfo.value.album_id, newIndex);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 组件卸载时移除事件监听器
|
||||
onUnmounted(() => {
|
||||
@@ -446,10 +538,10 @@ onUnmounted(() => {
|
||||
@click="toggleMenu"
|
||||
:class="{ 'no-header': shouldHideHeader }">
|
||||
|
||||
<!-- <!– 始终可见的页码显示 –>-->
|
||||
<!-- <div class="page-indicator">-->
|
||||
<!-- {{ currentPageInfo }}-->
|
||||
<!-- </div>-->
|
||||
<!-- <!– 始终可见的页码显示 –>-->
|
||||
<!-- <div class="page-indicator">-->
|
||||
<!-- {{ currentPageInfo }}-->
|
||||
<!-- </div>-->
|
||||
|
||||
<!-- 顶部菜单栏 -->
|
||||
<div
|
||||
@@ -459,8 +551,18 @@ onUnmounted(() => {
|
||||
>
|
||||
<div class="menu-content">
|
||||
<span class="page-info">{{ currentPageInfo }}</span>
|
||||
<button @click="prevImage" :disabled="currentImageIndex === 0 || loading">上一张</button>
|
||||
<button @click="nextImage" :disabled="currentImageIndex === mangaImages.length - 1 || loading">下一张</button>
|
||||
<button
|
||||
@click="prevImage"
|
||||
:disabled="currentImageIndex <= 0 || loading || mangaImages.length === 0"
|
||||
>
|
||||
上一张
|
||||
</button>
|
||||
<button
|
||||
@click="nextImage"
|
||||
:disabled="currentImageIndex >= mangaImages.length - 1 || loading || mangaImages.length === 0"
|
||||
>
|
||||
下一张
|
||||
</button>
|
||||
<button @click="isFullscreen ? exitFullscreen() : enterFullscreen()">
|
||||
{{ isFullscreen ? '退出全屏' : '全屏' }}
|
||||
</button>
|
||||
@@ -481,7 +583,7 @@ onUnmounted(() => {
|
||||
>
|
||||
<div class="drawer-content">
|
||||
<div class="drawer-header">
|
||||
<h3>ReiJM</h3>
|
||||
<button @click="back" class="back-btn">ReiJM</button>
|
||||
<button @click="toggleDrawer" class="close-btn">×</button>
|
||||
</div>
|
||||
<div class="drawer-body">
|
||||
|
||||
@@ -32,8 +32,11 @@ const getUrlParameter = (name: string): string | null => {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const token = getUrlParameter('token')
|
||||
|
||||
let token = getUrlParameter('token')
|
||||
// 如果URL中没有token,则从localStorage中获取
|
||||
if (!token || token === 'error') {
|
||||
token = localStorage.getItem('token')
|
||||
}
|
||||
if (!token || token === 'error') {
|
||||
if (token === 'error') {
|
||||
error.value = '登录失败'
|
||||
@@ -42,8 +45,8 @@ onMounted(async () => {
|
||||
isLoggedIn.value = false
|
||||
return
|
||||
}
|
||||
//写到localStorage
|
||||
localStorage.setItem('token', token)
|
||||
//写到localStorage
|
||||
try {
|
||||
// 调用API获取用户信息(需要后端提供此接口)
|
||||
const response = await fetch(`/api/user/data`, { headers: { Token: `${token}` }})
|
||||
|
||||
2
reisa-admin/reisaAdminSpring/.gitattributes
vendored
Normal file
2
reisa-admin/reisaAdminSpring/.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
||||
33
reisa-admin/reisaAdminSpring/.gitignore
vendored
Normal file
33
reisa-admin/reisaAdminSpring/.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
3
reisa-admin/reisaAdminSpring/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
3
reisa-admin/reisaAdminSpring/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
wrapperVersion=3.3.4
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip
|
||||
295
reisa-admin/reisaAdminSpring/mvnw
vendored
Executable file
295
reisa-admin/reisaAdminSpring/mvnw
vendored
Executable file
@@ -0,0 +1,295 @@
|
||||
#!/bin/sh
|
||||
# ----------------------------------------------------------------------------
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Apache Maven Wrapper startup batch script, version 3.3.4
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
|
||||
# MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
set -euf
|
||||
[ "${MVNW_VERBOSE-}" != debug ] || set -x
|
||||
|
||||
# OS specific support.
|
||||
native_path() { printf %s\\n "$1"; }
|
||||
case "$(uname)" in
|
||||
CYGWIN* | MINGW*)
|
||||
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
|
||||
native_path() { cygpath --path --windows "$1"; }
|
||||
;;
|
||||
esac
|
||||
|
||||
# set JAVACMD and JAVACCMD
|
||||
set_java_home() {
|
||||
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
|
||||
if [ -n "${JAVA_HOME-}" ]; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
JAVACCMD="$JAVA_HOME/jre/sh/javac"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
JAVACCMD="$JAVA_HOME/bin/javac"
|
||||
|
||||
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
|
||||
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
|
||||
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
JAVACMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v java
|
||||
)" || :
|
||||
JAVACCMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v javac
|
||||
)" || :
|
||||
|
||||
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
|
||||
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# hash string like Java String::hashCode
|
||||
hash_string() {
|
||||
str="${1:-}" h=0
|
||||
while [ -n "$str" ]; do
|
||||
char="${str%"${str#?}"}"
|
||||
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
|
||||
str="${str#?}"
|
||||
done
|
||||
printf %x\\n $h
|
||||
}
|
||||
|
||||
verbose() { :; }
|
||||
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
|
||||
|
||||
die() {
|
||||
printf %s\\n "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
trim() {
|
||||
# MWRAPPER-139:
|
||||
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
|
||||
# Needed for removing poorly interpreted newline sequences when running in more
|
||||
# exotic environments such as mingw bash on Windows.
|
||||
printf "%s" "${1}" | tr -d '[:space:]'
|
||||
}
|
||||
|
||||
scriptDir="$(dirname "$0")"
|
||||
scriptName="$(basename "$0")"
|
||||
|
||||
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
|
||||
while IFS="=" read -r key value; do
|
||||
case "${key-}" in
|
||||
distributionUrl) distributionUrl=$(trim "${value-}") ;;
|
||||
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
|
||||
esac
|
||||
done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||
|
||||
case "${distributionUrl##*/}" in
|
||||
maven-mvnd-*bin.*)
|
||||
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
|
||||
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
|
||||
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
|
||||
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
|
||||
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
|
||||
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
|
||||
*)
|
||||
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
|
||||
distributionPlatform=linux-amd64
|
||||
;;
|
||||
esac
|
||||
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
|
||||
;;
|
||||
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
|
||||
*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
|
||||
esac
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
distributionUrlNameMain="${distributionUrlName%.*}"
|
||||
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
|
||||
MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
|
||||
MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
|
||||
|
||||
exec_maven() {
|
||||
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
|
||||
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
|
||||
}
|
||||
|
||||
if [ -d "$MAVEN_HOME" ]; then
|
||||
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
exec_maven "$@"
|
||||
fi
|
||||
|
||||
case "${distributionUrl-}" in
|
||||
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
|
||||
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
|
||||
esac
|
||||
|
||||
# prepare tmp dir
|
||||
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
|
||||
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
|
||||
trap clean HUP INT TERM EXIT
|
||||
else
|
||||
die "cannot create temp dir"
|
||||
fi
|
||||
|
||||
mkdir -p -- "${MAVEN_HOME%/*}"
|
||||
|
||||
# Download and Install Apache Maven
|
||||
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
verbose "Downloading from: $distributionUrl"
|
||||
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
# select .zip or .tar.gz
|
||||
if ! command -v unzip >/dev/null; then
|
||||
distributionUrl="${distributionUrl%.zip}.tar.gz"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
fi
|
||||
|
||||
# verbose opt
|
||||
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
|
||||
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
|
||||
|
||||
# normalize http auth
|
||||
case "${MVNW_PASSWORD:+has-password}" in
|
||||
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
esac
|
||||
|
||||
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
|
||||
verbose "Found wget ... using wget"
|
||||
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
|
||||
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
|
||||
verbose "Found curl ... using curl"
|
||||
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
|
||||
elif set_java_home; then
|
||||
verbose "Falling back to use Java to download"
|
||||
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
|
||||
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
cat >"$javaSource" <<-END
|
||||
public class Downloader extends java.net.Authenticator
|
||||
{
|
||||
protected java.net.PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
|
||||
}
|
||||
public static void main( String[] args ) throws Exception
|
||||
{
|
||||
setDefault( new Downloader() );
|
||||
java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
|
||||
}
|
||||
}
|
||||
END
|
||||
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
|
||||
verbose " - Compiling Downloader.java ..."
|
||||
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
|
||||
verbose " - Running Downloader.java ..."
|
||||
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
|
||||
fi
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
if [ -n "${distributionSha256Sum-}" ]; then
|
||||
distributionSha256Result=false
|
||||
if [ "$MVN_CMD" = mvnd.sh ]; then
|
||||
echo "Checksum validation is not supported for maven-mvnd." >&2
|
||||
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
elif command -v sha256sum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
elif command -v shasum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
else
|
||||
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
|
||||
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ $distributionSha256Result = false ]; then
|
||||
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
|
||||
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# unzip and move
|
||||
if command -v unzip >/dev/null; then
|
||||
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
|
||||
else
|
||||
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
|
||||
fi
|
||||
|
||||
# Find the actual extracted directory name (handles snapshots where filename != directory name)
|
||||
actualDistributionDir=""
|
||||
|
||||
# First try the expected directory name (for regular distributions)
|
||||
if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then
|
||||
if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then
|
||||
actualDistributionDir="$distributionUrlNameMain"
|
||||
fi
|
||||
fi
|
||||
|
||||
# If not found, search for any directory with the Maven executable (for snapshots)
|
||||
if [ -z "$actualDistributionDir" ]; then
|
||||
# enable globbing to iterate over items
|
||||
set +f
|
||||
for dir in "$TMP_DOWNLOAD_DIR"/*; do
|
||||
if [ -d "$dir" ]; then
|
||||
if [ -f "$dir/bin/$MVN_CMD" ]; then
|
||||
actualDistributionDir="$(basename "$dir")"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
set -f
|
||||
fi
|
||||
|
||||
if [ -z "$actualDistributionDir" ]; then
|
||||
verbose "Contents of $TMP_DOWNLOAD_DIR:"
|
||||
verbose "$(ls -la "$TMP_DOWNLOAD_DIR")"
|
||||
die "Could not find Maven distribution directory in extracted archive"
|
||||
fi
|
||||
|
||||
verbose "Found extracted Maven distribution directory: $actualDistributionDir"
|
||||
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url"
|
||||
mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
||||
|
||||
clean || :
|
||||
exec_maven "$@"
|
||||
189
reisa-admin/reisaAdminSpring/mvnw.cmd
vendored
Normal file
189
reisa-admin/reisaAdminSpring/mvnw.cmd
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
<# : batch portion
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||
@REM or more contributor license agreements. See the NOTICE file
|
||||
@REM distributed with this work for additional information
|
||||
@REM regarding copyright ownership. The ASF licenses this file
|
||||
@REM to you under the Apache License, Version 2.0 (the
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@REM KIND, either express or implied. See the License for the
|
||||
@REM specific language governing permissions and limitations
|
||||
@REM under the License.
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Apache Maven Wrapper startup batch script, version 3.3.4
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
|
||||
@SET __MVNW_CMD__=
|
||||
@SET __MVNW_ERROR__=
|
||||
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
|
||||
@SET PSModulePath=
|
||||
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
|
||||
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
|
||||
)
|
||||
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
|
||||
@SET __MVNW_PSMODULEP_SAVE=
|
||||
@SET __MVNW_ARG0_NAME__=
|
||||
@SET MVNW_USERNAME=
|
||||
@SET MVNW_PASSWORD=
|
||||
@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*)
|
||||
@echo Cannot start maven from wrapper >&2 && exit /b 1
|
||||
@GOTO :EOF
|
||||
: end batch / begin powershell #>
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
if ($env:MVNW_VERBOSE -eq "true") {
|
||||
$VerbosePreference = "Continue"
|
||||
}
|
||||
|
||||
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
|
||||
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
|
||||
if (!$distributionUrl) {
|
||||
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||
}
|
||||
|
||||
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
|
||||
"maven-mvnd-*" {
|
||||
$USE_MVND = $true
|
||||
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
|
||||
$MVN_CMD = "mvnd.cmd"
|
||||
break
|
||||
}
|
||||
default {
|
||||
$USE_MVND = $false
|
||||
$MVN_CMD = $script -replace '^mvnw','mvn'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
if ($env:MVNW_REPOURL) {
|
||||
$MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" }
|
||||
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')"
|
||||
}
|
||||
$distributionUrlName = $distributionUrl -replace '^.*/',''
|
||||
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
|
||||
|
||||
$MAVEN_M2_PATH = "$HOME/.m2"
|
||||
if ($env:MAVEN_USER_HOME) {
|
||||
$MAVEN_M2_PATH = "$env:MAVEN_USER_HOME"
|
||||
}
|
||||
|
||||
if (-not (Test-Path -Path $MAVEN_M2_PATH)) {
|
||||
New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null
|
||||
}
|
||||
|
||||
$MAVEN_WRAPPER_DISTS = $null
|
||||
if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) {
|
||||
$MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
|
||||
} else {
|
||||
$MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists"
|
||||
}
|
||||
|
||||
$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain"
|
||||
$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
|
||||
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
|
||||
|
||||
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
|
||||
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
exit $?
|
||||
}
|
||||
|
||||
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
|
||||
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
|
||||
}
|
||||
|
||||
# prepare tmp dir
|
||||
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
|
||||
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
|
||||
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
|
||||
trap {
|
||||
if ($TMP_DOWNLOAD_DIR.Exists) {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
}
|
||||
|
||||
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
|
||||
|
||||
# Download and Install Apache Maven
|
||||
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
Write-Verbose "Downloading from: $distributionUrl"
|
||||
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
|
||||
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
|
||||
}
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
|
||||
if ($distributionSha256Sum) {
|
||||
if ($USE_MVND) {
|
||||
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
|
||||
}
|
||||
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
|
||||
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
|
||||
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
|
||||
}
|
||||
}
|
||||
|
||||
# unzip and move
|
||||
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
|
||||
|
||||
# Find the actual extracted directory name (handles snapshots where filename != directory name)
|
||||
$actualDistributionDir = ""
|
||||
|
||||
# First try the expected directory name (for regular distributions)
|
||||
$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain"
|
||||
$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD"
|
||||
if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) {
|
||||
$actualDistributionDir = $distributionUrlNameMain
|
||||
}
|
||||
|
||||
# If not found, search for any directory with the Maven executable (for snapshots)
|
||||
if (!$actualDistributionDir) {
|
||||
Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object {
|
||||
$testPath = Join-Path $_.FullName "bin/$MVN_CMD"
|
||||
if (Test-Path -Path $testPath -PathType Leaf) {
|
||||
$actualDistributionDir = $_.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$actualDistributionDir) {
|
||||
Write-Error "Could not find Maven distribution directory in extracted archive"
|
||||
}
|
||||
|
||||
Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir"
|
||||
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null
|
||||
try {
|
||||
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
|
||||
} catch {
|
||||
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
|
||||
Write-Error "fail to move MAVEN_HOME"
|
||||
}
|
||||
} finally {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
77
reisa-admin/reisaAdminSpring/pom.xml
Normal file
77
reisa-admin/reisaAdminSpring/pom.xml
Normal file
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>org.ast</groupId>
|
||||
<artifactId>reisaAdminSpring</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>reisaAdminSpring</name>
|
||||
<description>reisaAdminSpring</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>25</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
<version>3.4.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.12.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- JSch library for SSH connections -->
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
<artifactId>jsch</artifactId>
|
||||
<version>0.1.55</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.ast.reisaadminspring;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class ReisaAdminSpringApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ReisaAdminSpringApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package org.ast.reisaadminspring.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.ast.reisaadminspring.been.Server;
|
||||
import org.ast.reisaadminspring.been.Status;
|
||||
import org.ast.reisaadminspring.dao.ServerDao;
|
||||
import org.ast.reisaadminspring.dao.StatusDao;
|
||||
import org.ast.reisaadminspring.service.SystemStatusService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1")
|
||||
public class ApiServerV1 {
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ApiServerV1.class);
|
||||
@Autowired
|
||||
private ServerDao serverDao;
|
||||
@Autowired
|
||||
private StatusDao statusDao;
|
||||
@Autowired
|
||||
private SystemStatusService systemStatusService;
|
||||
private static Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(LocalDateTime.class, (JsonSerializer<LocalDateTime>) (src, typeOfSrc, context) ->
|
||||
new JsonPrimitive(src.toString()))
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
private static final Map<String, Status> statusMap = new ConcurrentHashMap<>();
|
||||
private static volatile List<Server> tempServerList = new CopyOnWriteArrayList<>();
|
||||
|
||||
@PostConstruct
|
||||
@Scheduled(fixedRate = 60000)
|
||||
public void updateStatus() {
|
||||
// 使用 CompletableFuture 异步执行每个服务器的状态获取
|
||||
for (String ip : statusMap.keySet()) {
|
||||
for (Server server : tempServerList) {
|
||||
if (server.getIpAddress().equals(ip)) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
log.info("Updating status for server: {}", server.getName());
|
||||
Status status = systemStatusService.getStatus(
|
||||
server.getIpAddress(),
|
||||
server.getSshUsername(),
|
||||
server.getSshPassword()
|
||||
);
|
||||
statusMap.put(ip, status);
|
||||
server.setOutIpAddress(status.getPublicIp());
|
||||
serverDao.save(server);
|
||||
statusDao.save(status);
|
||||
log.info("Status updated for server: {}", server.getName());
|
||||
} catch (Exception e) {
|
||||
// 异常处理
|
||||
log.error("Error updating status for server: {}", server.getName(), e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@GetMapping("/status/history/{ip}")
|
||||
public List<Status> getStatus(@PathVariable String ip, @RequestParam(defaultValue = "0", required = false) int limit) {
|
||||
List<Status> statuses = statusDao.findByHostOrderByTimestampDesc(ip);
|
||||
if (limit > 0) {
|
||||
return statuses.stream().limit(limit).collect(Collectors.toList());
|
||||
}
|
||||
return statuses;
|
||||
}
|
||||
|
||||
@GetMapping("/server")
|
||||
public List<Server> getAllServers() {
|
||||
List<Server> serverList = serverDao.findAll();
|
||||
|
||||
// 使用更高效的比较方式
|
||||
boolean needsUpdate = tempServerList.size() != serverList.size();
|
||||
if (!needsUpdate) {
|
||||
for (int i = 0; i < serverList.size(); i++) {
|
||||
if (!serverList.get(i).getId().equals(tempServerList.get(i).getId())) {
|
||||
needsUpdate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (needsUpdate) {
|
||||
tempServerList = new ArrayList<>(serverList);
|
||||
// 只更新变化的部分
|
||||
updateStatusMap(serverList);
|
||||
}
|
||||
|
||||
// 为每个服务器设置当前状态
|
||||
for (Server server : serverList) {
|
||||
server.setDevice(statusMap.get(server.getIpAddress()));
|
||||
}
|
||||
|
||||
return serverList;
|
||||
}
|
||||
|
||||
private void updateStatusMap(List<Server> serverList) {
|
||||
Set<String> currentIps = serverList.stream()
|
||||
.map(Server::getIpAddress)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 移除不再存在的服务器状态
|
||||
statusMap.keySet().removeIf(ip -> !currentIps.contains(ip));
|
||||
|
||||
// 添加新服务器的初始状态
|
||||
for (Server server : serverList) {
|
||||
if (server.getIpAddress() != null && !statusMap.containsKey(server.getIpAddress())) {
|
||||
statusMap.put(server.getIpAddress(), new Status());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/server")
|
||||
public Server addServer(@RequestBody Server server) {
|
||||
return serverDao.save(server);
|
||||
}
|
||||
@PutMapping("/server")
|
||||
public Server updateServer(@RequestBody Server server) {
|
||||
return serverDao.save(server);
|
||||
}
|
||||
@DeleteMapping("/server")
|
||||
public void deleteServer(@RequestBody Server server) {
|
||||
serverDao.delete(server);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package org.ast.reisaadminspring.been;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class Server {
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
private String place;
|
||||
private String ipAddress;
|
||||
private String outIpAddress;
|
||||
|
||||
private String status;
|
||||
|
||||
private int sshPort ;
|
||||
private String sshUsername;
|
||||
private String sshPassword;
|
||||
|
||||
private String baoTaLogin;
|
||||
private String baoTaUsername;
|
||||
private String baoTaPassword;
|
||||
|
||||
@Transient
|
||||
private Status device;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setStatus(Status device) {
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
public String getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
public Status getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
public void setDevice(Status device) {
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
public void setPlace(String place) {
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public int getSshPort() {
|
||||
return sshPort;
|
||||
}
|
||||
|
||||
public void setSshPort(int sshPort) {
|
||||
this.sshPort = sshPort;
|
||||
}
|
||||
|
||||
public String getSshUsername() {
|
||||
return sshUsername;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public void setSshUsername(String sshUsername) {
|
||||
this.sshUsername = sshUsername;
|
||||
}
|
||||
|
||||
public String getSshPassword() {
|
||||
return sshPassword;
|
||||
}
|
||||
|
||||
public void setSshPassword(String sshPassword) {
|
||||
this.sshPassword = sshPassword;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getIpAddress() {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
public void setIpAddress(String ipAddress) {
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
|
||||
public String getOutIpAddress() {
|
||||
return outIpAddress;
|
||||
}
|
||||
|
||||
public void setOutIpAddress(String outIpAddress) {
|
||||
this.outIpAddress = outIpAddress;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getBaoTaLogin() {
|
||||
return baoTaLogin;
|
||||
}
|
||||
|
||||
public void setBaoTaLogin(String baoTaLogin) {
|
||||
this.baoTaLogin = baoTaLogin;
|
||||
}
|
||||
|
||||
public String getBaoTaUsername() {
|
||||
return baoTaUsername;
|
||||
}
|
||||
|
||||
public void setBaoTaUsername(String baoTaUsername) {
|
||||
this.baoTaUsername = baoTaUsername;
|
||||
}
|
||||
|
||||
public String getBaoTaPassword() {
|
||||
return baoTaPassword;
|
||||
}
|
||||
|
||||
public void setBaoTaPassword(String baoTaPassword) {
|
||||
this.baoTaPassword = baoTaPassword;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,579 @@
|
||||
package org.ast.reisaadminspring.been;
|
||||
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Document
|
||||
public class Status {
|
||||
private String id;
|
||||
private String host;
|
||||
private Long time;
|
||||
private LocalDateTime timestamp;
|
||||
private CpuInfo cpuInfo;
|
||||
private MemoryInfo memoryInfo;
|
||||
private List<GpuInfo> gpuInfo;
|
||||
private String uptime;
|
||||
private String publicIp;
|
||||
private List<DiskInfo> diskUsage;
|
||||
private List<NetworkInfo> networkInfo;
|
||||
private List<ProcessInfo> processes;
|
||||
private LoadAverage loadAverage;
|
||||
private String systemInfo;
|
||||
private String error;
|
||||
|
||||
// Constructors
|
||||
public Status() {}
|
||||
|
||||
public Long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setTime(Long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public LocalDateTime getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(LocalDateTime timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public CpuInfo getCpuInfo() {
|
||||
return cpuInfo;
|
||||
}
|
||||
|
||||
public void setCpuInfo(CpuInfo cpuInfo) {
|
||||
this.cpuInfo = cpuInfo;
|
||||
}
|
||||
|
||||
public MemoryInfo getMemoryInfo() {
|
||||
return memoryInfo;
|
||||
}
|
||||
|
||||
public void setMemoryInfo(MemoryInfo memoryInfo) {
|
||||
this.memoryInfo = memoryInfo;
|
||||
}
|
||||
|
||||
public List<GpuInfo> getGpuInfo() {
|
||||
return gpuInfo;
|
||||
}
|
||||
|
||||
public void setGpuInfo(List<GpuInfo> gpuInfo) {
|
||||
this.gpuInfo = gpuInfo;
|
||||
}
|
||||
|
||||
public String getUptime() {
|
||||
return uptime;
|
||||
}
|
||||
|
||||
public void setUptime(String uptime) {
|
||||
this.uptime = uptime;
|
||||
}
|
||||
|
||||
public String getPublicIp() {
|
||||
return publicIp;
|
||||
}
|
||||
|
||||
public void setPublicIp(String publicIp) {
|
||||
this.publicIp = publicIp;
|
||||
}
|
||||
|
||||
public List<DiskInfo> getDiskUsage() {
|
||||
return diskUsage;
|
||||
}
|
||||
|
||||
public void setDiskUsage(List<DiskInfo> diskUsage) {
|
||||
this.diskUsage = diskUsage;
|
||||
}
|
||||
|
||||
public List<NetworkInfo> getNetworkInfo() {
|
||||
return networkInfo;
|
||||
}
|
||||
|
||||
public void setNetworkInfo(List<NetworkInfo> networkInfo) {
|
||||
this.networkInfo = networkInfo;
|
||||
}
|
||||
|
||||
public List<ProcessInfo> getProcesses() {
|
||||
return processes;
|
||||
}
|
||||
|
||||
public void setProcesses(List<ProcessInfo> processes) {
|
||||
this.processes = processes;
|
||||
}
|
||||
|
||||
public LoadAverage getLoadAverage() {
|
||||
return loadAverage;
|
||||
}
|
||||
|
||||
public void setLoadAverage(LoadAverage loadAverage) {
|
||||
this.loadAverage = loadAverage;
|
||||
}
|
||||
|
||||
public String getSystemInfo() {
|
||||
return systemInfo;
|
||||
}
|
||||
|
||||
public void setSystemInfo(String systemInfo) {
|
||||
this.systemInfo = systemInfo;
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(String error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
// 内部类定义
|
||||
public static class CpuInfo {
|
||||
private String modelName;
|
||||
private int sockets;
|
||||
private int coresPerSocket;
|
||||
private int threadsPerCore;
|
||||
private double usagePercent;
|
||||
|
||||
// Getters and Setters
|
||||
public String getModelName() {
|
||||
return modelName;
|
||||
}
|
||||
|
||||
public void setModelName(String modelName) {
|
||||
this.modelName = modelName;
|
||||
}
|
||||
|
||||
public int getSockets() {
|
||||
return sockets;
|
||||
}
|
||||
|
||||
public void setSockets(int sockets) {
|
||||
this.sockets = sockets;
|
||||
}
|
||||
|
||||
public int getCoresPerSocket() {
|
||||
return coresPerSocket;
|
||||
}
|
||||
|
||||
public void setCoresPerSocket(int coresPerSocket) {
|
||||
this.coresPerSocket = coresPerSocket;
|
||||
}
|
||||
|
||||
public int getThreadsPerCore() {
|
||||
return threadsPerCore;
|
||||
}
|
||||
|
||||
public void setThreadsPerCore(int threadsPerCore) {
|
||||
this.threadsPerCore = threadsPerCore;
|
||||
}
|
||||
|
||||
public double getUsagePercent() {
|
||||
return usagePercent;
|
||||
}
|
||||
|
||||
public void setUsagePercent(double usagePercent) {
|
||||
this.usagePercent = usagePercent;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MemoryInfo {
|
||||
private long totalBytes;
|
||||
private long usedBytes;
|
||||
private long freeBytes;
|
||||
private long sharedBytes;
|
||||
private long buffCacheBytes;
|
||||
private long availableBytes;
|
||||
private double usagePercent;
|
||||
|
||||
// Getters and Setters
|
||||
public long getTotalBytes() {
|
||||
return totalBytes;
|
||||
}
|
||||
|
||||
public void setTotalBytes(long totalBytes) {
|
||||
this.totalBytes = totalBytes;
|
||||
}
|
||||
|
||||
public long getUsedBytes() {
|
||||
return usedBytes;
|
||||
}
|
||||
|
||||
public void setUsedBytes(long usedBytes) {
|
||||
this.usedBytes = usedBytes;
|
||||
}
|
||||
|
||||
public long getFreeBytes() {
|
||||
return freeBytes;
|
||||
}
|
||||
|
||||
public void setFreeBytes(long freeBytes) {
|
||||
this.freeBytes = freeBytes;
|
||||
}
|
||||
|
||||
public long getSharedBytes() {
|
||||
return sharedBytes;
|
||||
}
|
||||
|
||||
public void setSharedBytes(long sharedBytes) {
|
||||
this.sharedBytes = sharedBytes;
|
||||
}
|
||||
|
||||
public long getBuffCacheBytes() {
|
||||
return buffCacheBytes;
|
||||
}
|
||||
|
||||
public void setBuffCacheBytes(long buffCacheBytes) {
|
||||
this.buffCacheBytes = buffCacheBytes;
|
||||
}
|
||||
|
||||
public long getAvailableBytes() {
|
||||
return availableBytes;
|
||||
}
|
||||
|
||||
public void setAvailableBytes(long availableBytes) {
|
||||
this.availableBytes = availableBytes;
|
||||
}
|
||||
|
||||
public double getUsagePercent() {
|
||||
return usagePercent;
|
||||
}
|
||||
|
||||
public void setUsagePercent(double usagePercent) {
|
||||
this.usagePercent = usagePercent;
|
||||
}
|
||||
}
|
||||
|
||||
// 在 Status.java 中更新 GpuInfo 类
|
||||
public static class GpuInfo {
|
||||
private String name;
|
||||
private long memoryUsedBytes;
|
||||
private long memoryTotalBytes;
|
||||
private double gpuUtilizationPercent;
|
||||
private List<GpuProcess> processes; // 新增GPU进程信息
|
||||
|
||||
// Getters and Setters
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getMemoryUsedBytes() {
|
||||
return memoryUsedBytes;
|
||||
}
|
||||
|
||||
public void setMemoryUsedBytes(long memoryUsedBytes) {
|
||||
this.memoryUsedBytes = memoryUsedBytes;
|
||||
}
|
||||
|
||||
public long getMemoryTotalBytes() {
|
||||
return memoryTotalBytes;
|
||||
}
|
||||
|
||||
public void setMemoryTotalBytes(long memoryTotalBytes) {
|
||||
this.memoryTotalBytes = memoryTotalBytes;
|
||||
}
|
||||
|
||||
public double getGpuUtilizationPercent() {
|
||||
return gpuUtilizationPercent;
|
||||
}
|
||||
|
||||
public void setGpuUtilizationPercent(double gpuUtilizationPercent) {
|
||||
this.gpuUtilizationPercent = gpuUtilizationPercent;
|
||||
}
|
||||
|
||||
public List<GpuProcess> getProcesses() {
|
||||
return processes;
|
||||
}
|
||||
|
||||
public void setProcesses(List<GpuProcess> processes) {
|
||||
this.processes = processes;
|
||||
}
|
||||
|
||||
// GPU进程信息内部类
|
||||
public static class GpuProcess {
|
||||
private int pid;
|
||||
private String processName;
|
||||
private long usedGpuMemoryBytes;
|
||||
private double gpuUtilizationPercent;
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getProcessName() {
|
||||
return processName;
|
||||
}
|
||||
|
||||
public void setProcessName(String processName) {
|
||||
this.processName = processName;
|
||||
}
|
||||
|
||||
public long getUsedGpuMemoryBytes() {
|
||||
return usedGpuMemoryBytes;
|
||||
}
|
||||
|
||||
public void setUsedGpuMemoryBytes(long usedGpuMemoryBytes) {
|
||||
this.usedGpuMemoryBytes = usedGpuMemoryBytes;
|
||||
}
|
||||
|
||||
public double getGpuUtilizationPercent() {
|
||||
return gpuUtilizationPercent;
|
||||
}
|
||||
|
||||
public void setGpuUtilizationPercent(double gpuUtilizationPercent) {
|
||||
this.gpuUtilizationPercent = gpuUtilizationPercent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DiskInfo {
|
||||
private String filesystem;
|
||||
private long sizeBytes;
|
||||
private long usedBytes;
|
||||
private long availableBytes;
|
||||
private double usagePercent;
|
||||
private String mountPoint;
|
||||
|
||||
// Getters and Setters
|
||||
public String getFilesystem() {
|
||||
return filesystem;
|
||||
}
|
||||
|
||||
public void setFilesystem(String filesystem) {
|
||||
this.filesystem = filesystem;
|
||||
}
|
||||
|
||||
public long getSizeBytes() {
|
||||
return sizeBytes;
|
||||
}
|
||||
|
||||
public void setSizeBytes(long sizeBytes) {
|
||||
this.sizeBytes = sizeBytes;
|
||||
}
|
||||
|
||||
public long getUsedBytes() {
|
||||
return usedBytes;
|
||||
}
|
||||
|
||||
public void setUsedBytes(long usedBytes) {
|
||||
this.usedBytes = usedBytes;
|
||||
}
|
||||
|
||||
public long getAvailableBytes() {
|
||||
return availableBytes;
|
||||
}
|
||||
|
||||
public void setAvailableBytes(long availableBytes) {
|
||||
this.availableBytes = availableBytes;
|
||||
}
|
||||
|
||||
public double getUsagePercent() {
|
||||
return usagePercent;
|
||||
}
|
||||
|
||||
public void setUsagePercent(double usagePercent) {
|
||||
this.usagePercent = usagePercent;
|
||||
}
|
||||
|
||||
public String getMountPoint() {
|
||||
return mountPoint;
|
||||
}
|
||||
|
||||
public void setMountPoint(String mountPoint) {
|
||||
this.mountPoint = mountPoint;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NetworkInfo {
|
||||
private String interfaceName;
|
||||
private String status;
|
||||
private List<String> ipAddresses;
|
||||
|
||||
// Getters and Setters
|
||||
public String getInterfaceName() {
|
||||
return interfaceName;
|
||||
}
|
||||
|
||||
public void setInterfaceName(String interfaceName) {
|
||||
this.interfaceName = interfaceName;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public List<String> getIpAddresses() {
|
||||
return ipAddresses;
|
||||
}
|
||||
|
||||
public void setIpAddresses(List<String> ipAddresses) {
|
||||
this.ipAddresses = ipAddresses;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProcessInfo {
|
||||
private String user;
|
||||
private int pid;
|
||||
private double cpuPercent;
|
||||
private double memoryPercent;
|
||||
private long virtualMemorySize;
|
||||
private long residentSetSize;
|
||||
private String tty;
|
||||
private String state;
|
||||
private String startTime;
|
||||
private String time;
|
||||
private String command;
|
||||
|
||||
// Getters and Setters
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public double getCpuPercent() {
|
||||
return cpuPercent;
|
||||
}
|
||||
|
||||
public void setCpuPercent(double cpuPercent) {
|
||||
this.cpuPercent = cpuPercent;
|
||||
}
|
||||
|
||||
public double getMemoryPercent() {
|
||||
return memoryPercent;
|
||||
}
|
||||
|
||||
public void setMemoryPercent(double memoryPercent) {
|
||||
this.memoryPercent = memoryPercent;
|
||||
}
|
||||
|
||||
public long getVirtualMemorySize() {
|
||||
return virtualMemorySize;
|
||||
}
|
||||
|
||||
public void setVirtualMemorySize(long virtualMemorySize) {
|
||||
this.virtualMemorySize = virtualMemorySize;
|
||||
}
|
||||
|
||||
public long getResidentSetSize() {
|
||||
return residentSetSize;
|
||||
}
|
||||
|
||||
public void setResidentSetSize(long residentSetSize) {
|
||||
this.residentSetSize = residentSetSize;
|
||||
}
|
||||
|
||||
public String getTty() {
|
||||
return tty;
|
||||
}
|
||||
|
||||
public void setTty(String tty) {
|
||||
this.tty = tty;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(String startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public void setCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoadAverage {
|
||||
private double oneMinute;
|
||||
private double fiveMinutes;
|
||||
private double fifteenMinutes;
|
||||
|
||||
// Getters and Setters
|
||||
public double getOneMinute() {
|
||||
return oneMinute;
|
||||
}
|
||||
|
||||
public void setOneMinute(double oneMinute) {
|
||||
this.oneMinute = oneMinute;
|
||||
}
|
||||
|
||||
public double getFiveMinutes() {
|
||||
return fiveMinutes;
|
||||
}
|
||||
|
||||
public void setFiveMinutes(double fiveMinutes) {
|
||||
this.fiveMinutes = fiveMinutes;
|
||||
}
|
||||
|
||||
public double getFifteenMinutes() {
|
||||
return fifteenMinutes;
|
||||
}
|
||||
|
||||
public void setFifteenMinutes(double fifteenMinutes) {
|
||||
this.fifteenMinutes = fifteenMinutes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.ast.reisaadminspring.dao;
|
||||
|
||||
import org.ast.reisaadminspring.been.Server;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface ServerDao extends MongoRepository<Server, String> {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.ast.reisaadminspring.dao;
|
||||
|
||||
import org.ast.reisaadminspring.been.Server;
|
||||
import org.ast.reisaadminspring.been.Status;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public interface StatusDao extends MongoRepository<Status, String> {
|
||||
List<Status> findByHost(String host);
|
||||
|
||||
List<Status> findByHostOrderByTimestampDesc(String ip);
|
||||
}
|
||||
@@ -0,0 +1,449 @@
|
||||
package org.ast.reisaadminspring.service;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.jcraft.jsch.*;
|
||||
import org.ast.reisaadminspring.been.Status;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Service
|
||||
public class SystemStatusService {
|
||||
public static void main(String[] args) {
|
||||
SystemStatusService service = new SystemStatusService();
|
||||
Status status = service.getStatus("100.80.156.98", "mainrunner", "abcdef20060113");
|
||||
|
||||
Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(LocalDateTime.class, (JsonSerializer<LocalDateTime>) (src, typeOfSrc, context) ->
|
||||
new JsonPrimitive(src.toString()))
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
|
||||
System.out.println(gson.toJson(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过SSH获取远程Linux服务器的状态信息
|
||||
* @param host 主机地址
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @return Status对象,包含系统详细信息
|
||||
*/
|
||||
public Status getStatus(String host, String username, String password) {
|
||||
Status status = new Status();
|
||||
JSch jsch = new JSch();
|
||||
|
||||
try {
|
||||
Session session = jsch.getSession(username, host, 22);
|
||||
session.setPassword(password);
|
||||
|
||||
// 设置SSH配置
|
||||
java.util.Properties config = new java.util.Properties();
|
||||
config.put("StrictHostKeyChecking", "no");
|
||||
session.setConfig(config);
|
||||
|
||||
// 连接并认证
|
||||
session.connect(30000); // 30秒超时
|
||||
|
||||
// 获取系统信息
|
||||
status.setHost(host);
|
||||
status.setTimestamp(LocalDateTime.now());
|
||||
status.setCpuInfo(parseCpuInfo(getCpuInfo(session), getCpuUsage(session)));
|
||||
status.setMemoryInfo(parseMemoryInfo(getMemoryInfo(session), getMemoryUsage(session)));
|
||||
status.setGpuInfo(parseGpuInfo(getGpuInfo(session)));
|
||||
status.setUptime(getUptime(session));
|
||||
status.setPublicIp(getPublicIp(session));
|
||||
status.setDiskUsage(parseDiskInfo(getDiskUsage(session)));
|
||||
status.setNetworkInfo(parseNetworkInfo(getNetworkInfo(session)));
|
||||
status.setProcesses(parseProcesses(getProcesses(session)));
|
||||
status.setLoadAverage(parseLoadAverage(getLoadAverage(session)));
|
||||
status.setSystemInfo(getSystemInfo(session));
|
||||
status.setTime(System.currentTimeMillis());
|
||||
session.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// 处理异常情况
|
||||
status.setError(e.getMessage());
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取CPU信息
|
||||
*/
|
||||
private String getCpuInfo(Session session) throws Exception {
|
||||
return executeCommand(session, "LANG=en_US.UTF-8 lscpu | grep -E 'Model name|Socket|Core|Thread'");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取CPU使用率
|
||||
*/
|
||||
private String getCpuUsage(Session session) throws Exception {
|
||||
return executeCommand(session, "LANG=en_US.UTF-8 top -bn1 | grep 'Cpu(s)' | awk '{print $2}' | sed 's/us,//'");
|
||||
}
|
||||
/**
|
||||
* 获取GPU信息 (NVIDIA)
|
||||
*/
|
||||
private String getGpuInfo(Session session) throws Exception {
|
||||
try {
|
||||
// 获取GPU基本信息
|
||||
String basicInfo = executeCommand(session, "nvidia-smi --query-gpu=name,memory.used,memory.total,utilization.gpu --format=csv");
|
||||
// 获取GPU进程信息
|
||||
String processInfo = executeCommand(session, "nvidia-smi pmon -c 1");
|
||||
|
||||
return basicInfo + "\n---PROCESS_INFO---\n" + processInfo;
|
||||
} catch (Exception e) {
|
||||
return "No NVIDIA GPU detected or nvidia-smi not available";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内存信息
|
||||
*/
|
||||
private String getMemoryInfo(Session session) throws Exception {
|
||||
return executeCommand(session, "LANG=en_US.UTF-8 free -b | grep Mem"); // 使用字节单位
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内存使用率
|
||||
*/
|
||||
private String getMemoryUsage(Session session) throws Exception {
|
||||
return executeCommand(session, "LANG=en_US.UTF-8 free | grep Mem | awk '{printf(\"%.2f\"), $3/$2 * 100.0}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统运行时间
|
||||
*/
|
||||
private String getUptime(Session session) throws Exception {
|
||||
return executeCommand(session, "LANG=en_US.UTF-8 uptime -p");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公网IP地址
|
||||
*/
|
||||
private String getPublicIp(Session session) throws Exception {
|
||||
try {
|
||||
return executeCommand(session, "curl -s icanhazip.com");
|
||||
} catch (Exception e) {
|
||||
return "Unable to retrieve public IP";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取磁盘使用情况
|
||||
*/
|
||||
private String getDiskUsage(Session session) throws Exception {
|
||||
return executeCommand(session, "LANG=en_US.UTF-8 df -B1 | grep -E '^/dev/'"); // 使用字节单位
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取网络接口信息
|
||||
*/
|
||||
private String getNetworkInfo(Session session) throws Exception {
|
||||
return executeCommand(session, "LANG=en_US.UTF-8 ip -br addr show | grep UP");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取进程列表 (前10个最占用资源的进程)
|
||||
*/
|
||||
private String getProcesses(Session session) throws Exception {
|
||||
return executeCommand(session, "LANG=en_US.UTF-8 ps aux --sort=-%cpu | head -11");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统负载
|
||||
*/
|
||||
private String getLoadAverage(Session session) throws Exception {
|
||||
return executeCommand(session, "LANG=en_US.UTF-8 uptime | awk -F'load average:' '{print $2}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统基本信息
|
||||
*/
|
||||
private String getSystemInfo(Session session) throws Exception {
|
||||
return executeCommand(session, "LANG=en_US.UTF-8 uname -a");
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行SSH命令
|
||||
*/
|
||||
private String executeCommand(Session session, String command) throws Exception {
|
||||
ChannelExec channel = (ChannelExec) session.openChannel("exec");
|
||||
channel.setCommand(command);
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInputStream()));
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
channel.connect();
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line).append("\n");
|
||||
}
|
||||
|
||||
channel.disconnect();
|
||||
return output.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析CPU信息
|
||||
*/
|
||||
private Status.CpuInfo parseCpuInfo(String cpuInfoStr, String cpuUsageStr) {
|
||||
Status.CpuInfo cpuInfo = new Status.CpuInfo();
|
||||
if (cpuInfoStr != null && !cpuInfoStr.isEmpty()) {
|
||||
String[] lines = cpuInfoStr.split("\n");
|
||||
for (String line : lines) {
|
||||
|
||||
if (line.contains("Model name:") && !line.contains("BIOS Model")) {
|
||||
// 处理不同的Model name格式
|
||||
String[] parts = line.split(":", 2); // 只分割第一个冒号
|
||||
if (parts.length >= 2) {
|
||||
cpuInfo.setModelName(parts[1].trim());
|
||||
}
|
||||
} else if (line.contains("Model name:") && line.contains("BIOS Model")) {
|
||||
String[] parts = line.split(":", 2);
|
||||
cpuInfo.setModelName(cpuInfo.getModelName() + " " + parts[1].trim().replace(cpuInfo.getModelName(),""));
|
||||
} else if (line.contains("Socket(s):")) {
|
||||
try {
|
||||
String value = line.split(":")[1].trim();
|
||||
// 处理可能包含额外描述的情况
|
||||
value = value.split("\\s+")[0]; // 只取第一个数字部分
|
||||
cpuInfo.setSockets(Integer.parseInt(value));
|
||||
} catch (NumberFormatException e) {
|
||||
cpuInfo.setSockets(1); // 默认值
|
||||
}
|
||||
} else if (line.contains("Core(s) per socket:")) {
|
||||
try {
|
||||
String value = line.split(":")[1].trim();
|
||||
value = value.split("\\s+")[0];
|
||||
cpuInfo.setCoresPerSocket(Integer.parseInt(value));
|
||||
} catch (NumberFormatException e) {
|
||||
cpuInfo.setCoresPerSocket(1);
|
||||
}
|
||||
} else if (line.contains("Thread(s) per core:")) {
|
||||
try {
|
||||
String value = line.split(":")[1].trim();
|
||||
value = value.split("\\s+")[0];
|
||||
cpuInfo.setThreadsPerCore(Integer.parseInt(value));
|
||||
} catch (NumberFormatException e) {
|
||||
cpuInfo.setThreadsPerCore(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cpuUsageStr != null && !cpuUsageStr.isEmpty()) {
|
||||
try {
|
||||
cpuInfo.setUsagePercent(Double.parseDouble(cpuUsageStr.replace("%", "").trim()));
|
||||
} catch (NumberFormatException e) {
|
||||
cpuInfo.setUsagePercent(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
return cpuInfo;
|
||||
}
|
||||
/**
|
||||
* 解析内存信息
|
||||
*/
|
||||
private Status.MemoryInfo parseMemoryInfo(String memoryInfoStr, String memoryUsageStr) {
|
||||
Status.MemoryInfo memoryInfo = new Status.MemoryInfo();
|
||||
|
||||
if (memoryInfoStr != null && !memoryInfoStr.isEmpty()) {
|
||||
String[] parts = memoryInfoStr.split("\\s+");
|
||||
if (parts.length >= 7) {
|
||||
try {
|
||||
memoryInfo.setTotalBytes(Long.parseLong(parts[1]));
|
||||
memoryInfo.setUsedBytes(Long.parseLong(parts[2]));
|
||||
memoryInfo.setFreeBytes(Long.parseLong(parts[3]));
|
||||
memoryInfo.setSharedBytes(Long.parseLong(parts[4]));
|
||||
memoryInfo.setBuffCacheBytes(Long.parseLong(parts[5]));
|
||||
memoryInfo.setAvailableBytes(Long.parseLong(parts[6]));
|
||||
} catch (NumberFormatException e) {
|
||||
// 忽略解析错误
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (memoryUsageStr != null && !memoryUsageStr.isEmpty()) {
|
||||
try {
|
||||
memoryInfo.setUsagePercent(Double.parseDouble(memoryUsageStr.trim()));
|
||||
} catch (NumberFormatException e) {
|
||||
memoryInfo.setUsagePercent(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
return memoryInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析GPU信息
|
||||
*/
|
||||
private List<Status.GpuInfo> parseGpuInfo(String gpuInfoStr) {
|
||||
List<Status.GpuInfo> gpuInfos = new ArrayList<>();
|
||||
if (gpuInfoStr != null && !gpuInfoStr.isEmpty() &&
|
||||
!gpuInfoStr.contains("No NVIDIA GPU detected")) {
|
||||
|
||||
String[] lines = gpuInfoStr.split("\n");
|
||||
for (int i = 1; i < lines.length; i++) { // 跳过标题行
|
||||
String[] parts = lines[i].split(",");
|
||||
if (parts.length >= 4) {
|
||||
Status.GpuInfo gpuInfo = new Status.GpuInfo();
|
||||
gpuInfo.setName(parts[0].trim());
|
||||
|
||||
try {
|
||||
// 解析内存使用情况 (去掉单位MiB)
|
||||
String memoryUsedStr = parts[1].trim().replace(" MiB", "");
|
||||
String memoryTotalStr = parts[2].trim().replace(" MiB", "");
|
||||
gpuInfo.setMemoryUsedBytes(Long.parseLong(memoryUsedStr) * 1024 * 1024);
|
||||
gpuInfo.setMemoryTotalBytes(Long.parseLong(memoryTotalStr) * 1024 * 1024);
|
||||
|
||||
// 解析GPU利用率 (去掉单位%)
|
||||
String utilizationStr = parts[3].trim().replace(" %", "");
|
||||
gpuInfo.setGpuUtilizationPercent(Double.parseDouble(utilizationStr));
|
||||
} catch (NumberFormatException e) {
|
||||
// 忽略解析错误
|
||||
}
|
||||
|
||||
gpuInfos.add(gpuInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return gpuInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析磁盘信息
|
||||
*/
|
||||
private List<Status.DiskInfo> parseDiskInfo(String diskInfoStr) {
|
||||
List<Status.DiskInfo> diskInfos = new ArrayList<>();
|
||||
|
||||
if (diskInfoStr != null && !diskInfoStr.isEmpty()) {
|
||||
String[] lines = diskInfoStr.split("\n");
|
||||
for (String line : lines) {
|
||||
String[] parts = line.trim().split("\\s+");
|
||||
if (parts.length >= 6) {
|
||||
Status.DiskInfo diskInfo = new Status.DiskInfo();
|
||||
diskInfo.setFilesystem(parts[0]);
|
||||
|
||||
try {
|
||||
diskInfo.setSizeBytes(Long.parseLong(parts[1]));
|
||||
diskInfo.setUsedBytes(Long.parseLong(parts[2]));
|
||||
diskInfo.setAvailableBytes(Long.parseLong(parts[3]));
|
||||
|
||||
// 解析使用百分比 (去掉%符号)
|
||||
String usagePercentStr = parts[4].replace("%", "");
|
||||
diskInfo.setUsagePercent(Double.parseDouble(usagePercentStr));
|
||||
|
||||
diskInfo.setMountPoint(parts[5]);
|
||||
} catch (NumberFormatException e) {
|
||||
// 忽略解析错误
|
||||
}
|
||||
|
||||
diskInfos.add(diskInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return diskInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析网络信息
|
||||
*/
|
||||
private List<Status.NetworkInfo> parseNetworkInfo(String networkInfoStr) {
|
||||
List<Status.NetworkInfo> networkInfos = new ArrayList<>();
|
||||
|
||||
if (networkInfoStr != null && !networkInfoStr.isEmpty()) {
|
||||
String[] lines = networkInfoStr.split("\n");
|
||||
for (String line : lines) {
|
||||
String[] parts = line.trim().split("\\s+");
|
||||
if (parts.length >= 3) {
|
||||
Status.NetworkInfo networkInfo = new Status.NetworkInfo();
|
||||
networkInfo.setInterfaceName(parts[0]);
|
||||
networkInfo.setStatus(parts[1]);
|
||||
|
||||
List<String> ipAddresses = new ArrayList<>();
|
||||
for (int i = 2; i < parts.length; i++) {
|
||||
ipAddresses.add(parts[i]);
|
||||
}
|
||||
networkInfo.setIpAddresses(ipAddresses);
|
||||
|
||||
networkInfos.add(networkInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return networkInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析进程信息
|
||||
*/
|
||||
private List<Status.ProcessInfo> parseProcesses(String processesStr) {
|
||||
List<Status.ProcessInfo> processInfos = new ArrayList<>();
|
||||
|
||||
if (processesStr != null && !processesStr.isEmpty()) {
|
||||
String[] lines = processesStr.split("\n");
|
||||
// 跳过标题行
|
||||
for (int i = 1; i < lines.length; i++) {
|
||||
String[] parts = lines[i].trim().split("\\s+", 11);
|
||||
if (parts.length >= 11) {
|
||||
Status.ProcessInfo processInfo = new Status.ProcessInfo();
|
||||
processInfo.setUser(parts[0]);
|
||||
|
||||
try {
|
||||
processInfo.setPid(Integer.parseInt(parts[1]));
|
||||
processInfo.setCpuPercent(Double.parseDouble(parts[2]));
|
||||
processInfo.setMemoryPercent(Double.parseDouble(parts[3]));
|
||||
processInfo.setVirtualMemorySize(Long.parseLong(parts[4]));
|
||||
processInfo.setResidentSetSize(Long.parseLong(parts[5]));
|
||||
processInfo.setTty(parts[6]);
|
||||
processInfo.setState(parts[7]);
|
||||
processInfo.setStartTime(parts[8]);
|
||||
processInfo.setTime(parts[9]);
|
||||
processInfo.setCommand(parts[10]);
|
||||
} catch (NumberFormatException e) {
|
||||
// 忽略解析错误
|
||||
}
|
||||
|
||||
processInfos.add(processInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return processInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析负载平均值
|
||||
*/
|
||||
private Status.LoadAverage parseLoadAverage(String loadAverageStr) {
|
||||
Status.LoadAverage loadAverage = new Status.LoadAverage();
|
||||
|
||||
if (loadAverageStr != null && !loadAverageStr.isEmpty()) {
|
||||
String[] parts = loadAverageStr.trim().split(",");
|
||||
if (parts.length >= 3) {
|
||||
try {
|
||||
loadAverage.setOneMinute(Double.parseDouble(parts[0].trim()));
|
||||
loadAverage.setFiveMinutes(Double.parseDouble(parts[1].trim()));
|
||||
loadAverage.setFifteenMinutes(Double.parseDouble(parts[2].trim()));
|
||||
} catch (NumberFormatException e) {
|
||||
// 忽略解析错误
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return loadAverage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
spring.application.name=reisaAdminSpring
|
||||
spring.data.mongodb.uri=mongodb://reisaAdmin:nbAC8hi8xdJeBDDT@100.80.156.98:27017/reisaadmin
|
||||
server.port=48102
|
||||
|
||||
spring.data.redis.host=127.0.0.1
|
||||
spring.data.redis.port: 6379
|
||||
1798
reisa-admin/src/App.vue
Normal file
1798
reisa-admin/src/App.vue
Normal file
File diff suppressed because it is too large
Load Diff
86
reisa-admin/src/assets/base.css
Normal file
86
reisa-admin/src/assets/base.css
Normal file
@@ -0,0 +1,86 @@
|
||||
/* color palette from <https://github.com/vuejs/theme> */
|
||||
:root {
|
||||
--vt-c-white: #ffffff;
|
||||
--vt-c-white-soft: #f8f8f8;
|
||||
--vt-c-white-mute: #f2f2f2;
|
||||
|
||||
--vt-c-black: #181818;
|
||||
--vt-c-black-soft: #222222;
|
||||
--vt-c-black-mute: #282828;
|
||||
|
||||
--vt-c-indigo: #2c3e50;
|
||||
|
||||
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
|
||||
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
|
||||
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
|
||||
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
|
||||
|
||||
--vt-c-text-light-1: var(--vt-c-indigo);
|
||||
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
|
||||
--vt-c-text-dark-1: var(--vt-c-white);
|
||||
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
|
||||
}
|
||||
|
||||
/* semantic color variables for this project */
|
||||
:root {
|
||||
--color-background: var(--vt-c-white);
|
||||
--color-background-soft: var(--vt-c-white-soft);
|
||||
--color-background-mute: var(--vt-c-white-mute);
|
||||
|
||||
--color-border: var(--vt-c-divider-light-2);
|
||||
--color-border-hover: var(--vt-c-divider-light-1);
|
||||
|
||||
--color-heading: var(--vt-c-text-light-1);
|
||||
--color-text: var(--vt-c-text-light-1);
|
||||
|
||||
--section-gap: 160px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--color-background: var(--vt-c-black);
|
||||
--color-background-soft: var(--vt-c-black-soft);
|
||||
--color-background-mute: var(--vt-c-black-mute);
|
||||
|
||||
--color-border: var(--vt-c-divider-dark-2);
|
||||
--color-border-hover: var(--vt-c-divider-dark-1);
|
||||
|
||||
--color-heading: var(--vt-c-text-dark-1);
|
||||
--color-text: var(--vt-c-text-dark-2);
|
||||
}
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
body {
|
||||
min-height: 100vh;
|
||||
color: var(--color-text);
|
||||
background: var(--color-background);
|
||||
transition:
|
||||
color 0.5s,
|
||||
background-color 0.5s;
|
||||
line-height: 1.6;
|
||||
font-family:
|
||||
Inter,
|
||||
-apple-system,
|
||||
BlinkMacSystemFont,
|
||||
'Segoe UI',
|
||||
Roboto,
|
||||
Oxygen,
|
||||
Ubuntu,
|
||||
Cantarell,
|
||||
'Fira Sans',
|
||||
'Droid Sans',
|
||||
'Helvetica Neue',
|
||||
sans-serif;
|
||||
font-size: 15px;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
1
reisa-admin/src/assets/logo.svg
Normal file
1
reisa-admin/src/assets/logo.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.76 226.69"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/></svg>
|
||||
|
After Width: | Height: | Size: 276 B |
35
reisa-admin/src/assets/main.css
Normal file
35
reisa-admin/src/assets/main.css
Normal file
@@ -0,0 +1,35 @@
|
||||
@import './base.css';
|
||||
|
||||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
a,
|
||||
.green {
|
||||
text-decoration: none;
|
||||
color: hsla(160, 100%, 37%, 1);
|
||||
transition: 0.4s;
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
a:hover {
|
||||
background-color: hsla(160, 100%, 37%, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
body {
|
||||
display: flex;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
#app {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
padding: 0 2rem;
|
||||
}
|
||||
}
|
||||
7
reisa-admin/src/components/icons/IconCommunity.vue
Normal file
7
reisa-admin/src/components/icons/IconCommunity.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
|
||||
<path
|
||||
d="M15 4a1 1 0 1 0 0 2V4zm0 11v-1a1 1 0 0 0-1 1h1zm0 4l-.707.707A1 1 0 0 0 16 19h-1zm-4-4l.707-.707A1 1 0 0 0 11 14v1zm-4.707-1.293a1 1 0 0 0-1.414 1.414l1.414-1.414zm-.707.707l-.707-.707.707.707zM9 11v-1a1 1 0 0 0-.707.293L9 11zm-4 0h1a1 1 0 0 0-1-1v1zm0 4H4a1 1 0 0 0 1.707.707L5 15zm10-9h2V4h-2v2zm2 0a1 1 0 0 1 1 1h2a3 3 0 0 0-3-3v2zm1 1v6h2V7h-2zm0 6a1 1 0 0 1-1 1v2a3 3 0 0 0 3-3h-2zm-1 1h-2v2h2v-2zm-3 1v4h2v-4h-2zm1.707 3.293l-4-4-1.414 1.414 4 4 1.414-1.414zM11 14H7v2h4v-2zm-4 0c-.276 0-.525-.111-.707-.293l-1.414 1.414C5.42 15.663 6.172 16 7 16v-2zm-.707 1.121l3.414-3.414-1.414-1.414-3.414 3.414 1.414 1.414zM9 12h4v-2H9v2zm4 0a3 3 0 0 0 3-3h-2a1 1 0 0 1-1 1v2zm3-3V3h-2v6h2zm0-6a3 3 0 0 0-3-3v2a1 1 0 0 1 1 1h2zm-3-3H3v2h10V0zM3 0a3 3 0 0 0-3 3h2a1 1 0 0 1 1-1V0zM0 3v6h2V3H0zm0 6a3 3 0 0 0 3 3v-2a1 1 0 0 1-1-1H0zm3 3h2v-2H3v2zm1-1v4h2v-4H4zm1.707 4.707l.586-.586-1.414-1.414-.586.586 1.414 1.414z"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
7
reisa-admin/src/components/icons/IconDocumentation.vue
Normal file
7
reisa-admin/src/components/icons/IconDocumentation.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" fill="currentColor">
|
||||
<path
|
||||
d="M11 2.253a1 1 0 1 0-2 0h2zm-2 13a1 1 0 1 0 2 0H9zm.447-12.167a1 1 0 1 0 1.107-1.666L9.447 3.086zM1 2.253L.447 1.42A1 1 0 0 0 0 2.253h1zm0 13H0a1 1 0 0 0 1.553.833L1 15.253zm8.447.833a1 1 0 1 0 1.107-1.666l-1.107 1.666zm0-14.666a1 1 0 1 0 1.107 1.666L9.447 1.42zM19 2.253h1a1 1 0 0 0-.447-.833L19 2.253zm0 13l-.553.833A1 1 0 0 0 20 15.253h-1zm-9.553-.833a1 1 0 1 0 1.107 1.666L9.447 14.42zM9 2.253v13h2v-13H9zm1.553-.833C9.203.523 7.42 0 5.5 0v2c1.572 0 2.961.431 3.947 1.086l1.107-1.666zM5.5 0C3.58 0 1.797.523.447 1.42l1.107 1.666C2.539 2.431 3.928 2 5.5 2V0zM0 2.253v13h2v-13H0zm1.553 13.833C2.539 15.431 3.928 15 5.5 15v-2c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM5.5 15c1.572 0 2.961.431 3.947 1.086l1.107-1.666C9.203 13.523 7.42 13 5.5 13v2zm5.053-11.914C11.539 2.431 12.928 2 14.5 2V0c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM14.5 2c1.573 0 2.961.431 3.947 1.086l1.107-1.666C18.203.523 16.421 0 14.5 0v2zm3.5.253v13h2v-13h-2zm1.553 12.167C18.203 13.523 16.421 13 14.5 13v2c1.573 0 2.961.431 3.947 1.086l1.107-1.666zM14.5 13c-1.92 0-3.703.523-5.053 1.42l1.107 1.666C11.539 15.431 12.928 15 14.5 15v-2z"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
7
reisa-admin/src/components/icons/IconEcosystem.vue
Normal file
7
reisa-admin/src/components/icons/IconEcosystem.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="20" fill="currentColor">
|
||||
<path
|
||||
d="M11.447 8.894a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm0 1.789a1 1 0 1 0 .894-1.789l-.894 1.789zM7.447 7.106a1 1 0 1 0-.894 1.789l.894-1.789zM10 9a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0H8zm9.447-5.606a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm2 .789a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zM18 5a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0h-2zm-5.447-4.606a1 1 0 1 0 .894-1.789l-.894 1.789zM9 1l.447-.894a1 1 0 0 0-.894 0L9 1zm-2.447.106a1 1 0 1 0 .894 1.789l-.894-1.789zm-6 3a1 1 0 1 0 .894 1.789L.553 4.106zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zm-2-.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 2.789a1 1 0 1 0 .894-1.789l-.894 1.789zM2 5a1 1 0 1 0-2 0h2zM0 7.5a1 1 0 1 0 2 0H0zm8.553 12.394a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 1a1 1 0 1 0 .894 1.789l-.894-1.789zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zM8 19a1 1 0 1 0 2 0H8zm2-2.5a1 1 0 1 0-2 0h2zm-7.447.394a1 1 0 1 0 .894-1.789l-.894 1.789zM1 15H0a1 1 0 0 0 .553.894L1 15zm1-2.5a1 1 0 1 0-2 0h2zm12.553 2.606a1 1 0 1 0 .894 1.789l-.894-1.789zM17 15l.447.894A1 1 0 0 0 18 15h-1zm1-2.5a1 1 0 1 0-2 0h2zm-7.447-5.394l-2 1 .894 1.789 2-1-.894-1.789zm-1.106 1l-2-1-.894 1.789 2 1 .894-1.789zM8 9v2.5h2V9H8zm8.553-4.894l-2 1 .894 1.789 2-1-.894-1.789zm.894 0l-2-1-.894 1.789 2 1 .894-1.789zM16 5v2.5h2V5h-2zm-4.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zm-2.894-1l-2 1 .894 1.789 2-1L8.553.106zM1.447 5.894l2-1-.894-1.789-2 1 .894 1.789zm-.894 0l2 1 .894-1.789-2-1-.894 1.789zM0 5v2.5h2V5H0zm9.447 13.106l-2-1-.894 1.789 2 1 .894-1.789zm0 1.789l2-1-.894-1.789-2 1 .894 1.789zM10 19v-2.5H8V19h2zm-6.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zM2 15v-2.5H0V15h2zm13.447 1.894l2-1-.894-1.789-2 1 .894 1.789zM18 15v-2.5h-2V15h2z"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
7
reisa-admin/src/components/icons/IconSupport.vue
Normal file
7
reisa-admin/src/components/icons/IconSupport.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
|
||||
<path
|
||||
d="M10 3.22l-.61-.6a5.5 5.5 0 0 0-7.666.105 5.5 5.5 0 0 0-.114 7.665L10 18.78l8.39-8.4a5.5 5.5 0 0 0-.114-7.665 5.5 5.5 0 0 0-7.666-.105l-.61.61z"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
19
reisa-admin/src/components/icons/IconTooling.vue
Normal file
19
reisa-admin/src/components/icons/IconTooling.vue
Normal file
@@ -0,0 +1,19 @@
|
||||
<!-- This icon is from <https://github.com/Templarian/MaterialDesign>, distributed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0) license-->
|
||||
<template>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
aria-hidden="true"
|
||||
role="img"
|
||||
class="iconify iconify--mdi"
|
||||
width="24"
|
||||
height="24"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
d="M20 18v-4h-3v1h-2v-1H9v1H7v-1H4v4h16M6.33 8l-1.74 4H7v-1h2v1h6v-1h2v1h2.41l-1.74-4H6.33M9 5v1h6V5H9m12.84 7.61c.1.22.16.48.16.8V18c0 .53-.21 1-.6 1.41c-.4.4-.85.59-1.4.59H4c-.55 0-1-.19-1.4-.59C2.21 19 2 18.53 2 18v-4.59c0-.32.06-.58.16-.8L4.5 7.22C4.84 6.41 5.45 6 6.33 6H7V5c0-.55.18-1 .57-1.41C7.96 3.2 8.44 3 9 3h6c.56 0 1.04.2 1.43.59c.39.41.57.86.57 1.41v1h.67c.88 0 1.49.41 1.83 1.22l2.34 5.39z"
|
||||
fill="currentColor"
|
||||
></path>
|
||||
</svg>
|
||||
</template>
|
||||
8
reisa-admin/src/main.js
Normal file
8
reisa-admin/src/main.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createApp } from 'vue';
|
||||
import App from './App.vue';
|
||||
import Antd from 'ant-design-vue';
|
||||
import 'ant-design-vue/dist/reset.css';
|
||||
|
||||
const app = createApp(App);
|
||||
app.use(Antd);
|
||||
app.mount('#app');
|
||||
Reference in New Issue
Block a user