mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-07 07:30:54 +08:00
Compare commits
20 Commits
codex/impl
...
codex/fix-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e65273daa6 | ||
|
|
d3a2acb605 | ||
|
|
bced24e47d | ||
|
|
425ad03e6f | ||
|
|
4462d8f711 | ||
|
|
1b31977ec6 | ||
|
|
42693cb1ff | ||
|
|
6b500466fc | ||
|
|
c84262eb88 | ||
|
|
fa2ffaa64a | ||
|
|
3037c856d0 | ||
|
|
7b1ce3f070 | ||
|
|
f4a15b3448 | ||
|
|
239f1f8c84 | ||
|
|
ac303184c4 | ||
|
|
7f16bbdb94 | ||
|
|
f1c83b0f68 | ||
|
|
22c2b1564d | ||
|
|
628d28c12d | ||
|
|
2577992ee3 |
@@ -38,6 +38,16 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vladsch.flexmark</groupId>
|
||||
<artifactId>flexmark-all</artifactId>
|
||||
<version>0.64.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.17.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
|
||||
@@ -119,6 +119,7 @@ public class SecurityConfig {
|
||||
.requestMatchers(HttpMethod.GET, "/api/reaction-types").permitAll()
|
||||
.requestMatchers(HttpMethod.GET, "/api/activities/**").permitAll()
|
||||
.requestMatchers(HttpMethod.GET, "/api/sitemap.xml").permitAll()
|
||||
.requestMatchers(HttpMethod.GET, "/api/rss").permitAll()
|
||||
.requestMatchers(HttpMethod.GET, "/api/point-goods").permitAll()
|
||||
.requestMatchers(HttpMethod.POST, "/api/point-goods").permitAll()
|
||||
.requestMatchers(HttpMethod.POST, "/api/categories/**").hasAuthority("ADMIN")
|
||||
@@ -154,7 +155,8 @@ public class SecurityConfig {
|
||||
uri.startsWith("/api/reaction-types") || uri.startsWith("/api/config") ||
|
||||
uri.startsWith("/api/activities") || uri.startsWith("/api/push/public-key") ||
|
||||
uri.startsWith("/api/point-goods") ||
|
||||
uri.startsWith("/api/sitemap.xml") || uri.startsWith("/api/medals"));
|
||||
uri.startsWith("/api/sitemap.xml") || uri.startsWith("/api/medals") ||
|
||||
uri.startsWith("/api/rss"));
|
||||
|
||||
if (authHeader != null && authHeader.startsWith("Bearer ")) {
|
||||
String token = authHeader.substring(7);
|
||||
|
||||
@@ -45,4 +45,14 @@ public class AdminPostController {
|
||||
public PostSummaryDto unpin(@PathVariable Long id) {
|
||||
return postMapper.toSummaryDto(postService.unpinPost(id));
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/rss-exclude")
|
||||
public PostSummaryDto excludeFromRss(@PathVariable Long id) {
|
||||
return postMapper.toSummaryDto(postService.excludeFromRss(id));
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/rss-include")
|
||||
public PostSummaryDto includeInRss(@PathVariable Long id) {
|
||||
return postMapper.toSummaryDto(postService.includeInRss(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,12 +48,13 @@ public class AuthController {
|
||||
}
|
||||
if (req.getInviteToken() != null && !req.getInviteToken().isEmpty()) {
|
||||
if (!inviteService.validate(req.getInviteToken())) {
|
||||
return ResponseEntity.badRequest().body(Map.of("error", "Invalid invite token"));
|
||||
return ResponseEntity.badRequest().body(Map.of("error", "邀请码使用次数过多"));
|
||||
}
|
||||
try {
|
||||
User user = userService.registerWithInvite(
|
||||
req.getUsername(), req.getEmail(), req.getPassword());
|
||||
inviteService.consume(req.getInviteToken());
|
||||
emailService.sendEmail(user.getEmail(), "在网站填写验证码以验证", "您的验证码是 " + user.getVerificationCode());
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"token", jwtService.generateToken(user.getUsername()),
|
||||
"reason_code", "INVITE_APPROVED"
|
||||
@@ -78,10 +79,26 @@ public class AuthController {
|
||||
public ResponseEntity<?> verify(@RequestBody VerifyRequest req) {
|
||||
boolean ok = userService.verifyCode(req.getUsername(), req.getCode());
|
||||
if (ok) {
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"message", "Verified",
|
||||
"token", jwtService.generateReasonToken(req.getUsername())
|
||||
));
|
||||
Optional<User> userOpt = userService.findByUsername(req.getUsername());
|
||||
if (userOpt.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("error", "Invalid credentials"));
|
||||
}
|
||||
|
||||
User user = userOpt.get();
|
||||
|
||||
if (user.isApproved()) {
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"message", "Verified and isApproved",
|
||||
"reason_code", "VERIFIED_AND_APPROVED",
|
||||
"token", jwtService.generateToken(req.getUsername())
|
||||
));
|
||||
} else {
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"message", "Verified",
|
||||
"reason_code", "VERIFIED",
|
||||
"token", jwtService.generateReasonToken(req.getUsername())
|
||||
));
|
||||
}
|
||||
}
|
||||
return ResponseEntity.badRequest().body(Map.of("error", "Invalid verification code"));
|
||||
}
|
||||
|
||||
282
backend/src/main/java/com/openisle/controller/RssController.java
Normal file
282
backend/src/main/java/com/openisle/controller/RssController.java
Normal file
@@ -0,0 +1,282 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.model.Post;
|
||||
import com.openisle.service.PostService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.safety.Safelist;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.vladsch.flexmark.ext.autolink.AutolinkExtension;
|
||||
import com.vladsch.flexmark.ext.tables.TablesExtension;
|
||||
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension;
|
||||
import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension;
|
||||
import com.vladsch.flexmark.html.HtmlRenderer;
|
||||
import com.vladsch.flexmark.parser.Parser;
|
||||
import com.vladsch.flexmark.util.data.MutableDataSet;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class RssController {
|
||||
private final PostService postService;
|
||||
|
||||
@Value("${app.website-url:https://www.open-isle.com}")
|
||||
private String websiteUrl;
|
||||
|
||||
// 兼容 Markdown/HTML 两类图片写法(用于 enclosure)
|
||||
private static final Pattern MD_IMAGE = Pattern.compile("!\\[[^\\]]*\\]\\(([^)]+)\\)");
|
||||
private static final Pattern HTML_IMAGE = Pattern.compile("<img[^>]+src=[\"']?([^\"'>]+)[\"']?[^>]*>");
|
||||
|
||||
private static final DateTimeFormatter RFC1123 = DateTimeFormatter.RFC_1123_DATE_TIME;
|
||||
|
||||
// flexmark:Markdown -> HTML
|
||||
private static final Parser MD_PARSER;
|
||||
private static final HtmlRenderer MD_RENDERER;
|
||||
static {
|
||||
MutableDataSet opts = new MutableDataSet();
|
||||
opts.set(Parser.EXTENSIONS, Arrays.asList(
|
||||
TablesExtension.create(),
|
||||
AutolinkExtension.create(),
|
||||
StrikethroughExtension.create(),
|
||||
TaskListExtension.create()
|
||||
));
|
||||
// 允许内联 HTML(下游再做 sanitize)
|
||||
opts.set(Parser.HTML_BLOCK_PARSER, true);
|
||||
MD_PARSER = Parser.builder(opts).build();
|
||||
MD_RENDERER = HtmlRenderer.builder(opts).escapeHtml(false).build();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/api/rss", produces = "application/rss+xml;charset=UTF-8")
|
||||
public String feed() {
|
||||
// 建议 20;你现在是 10,这里保留你的 10
|
||||
List<Post> posts = postService.listLatestRssPosts(10);
|
||||
String base = trimTrailingSlash(websiteUrl);
|
||||
|
||||
StringBuilder sb = new StringBuilder(4096);
|
||||
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
sb.append("<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">");
|
||||
sb.append("<channel>");
|
||||
elem(sb, "title", cdata("OpenIsle RSS"));
|
||||
elem(sb, "link", base + "/");
|
||||
elem(sb, "description", cdata("Latest posts"));
|
||||
ZonedDateTime updated = posts.stream()
|
||||
.map(p -> p.getCreatedAt().atZone(ZoneId.systemDefault()))
|
||||
.max(Comparator.naturalOrder())
|
||||
.orElse(ZonedDateTime.now());
|
||||
// channel lastBuildDate(GMT)
|
||||
elem(sb, "lastBuildDate", toRfc1123Gmt(updated));
|
||||
|
||||
for (Post p : posts) {
|
||||
String link = base + "/posts/" + p.getId();
|
||||
|
||||
// 1) Markdown -> HTML
|
||||
String html = renderMarkdown(p.getContent());
|
||||
|
||||
// 2) Sanitize(白名单增强)
|
||||
String safeHtml = sanitizeHtml(html);
|
||||
|
||||
// 3) 绝对化 href/src + 强制 rel/target
|
||||
String absHtml = absolutifyHtml(safeHtml, base);
|
||||
|
||||
// 4) 纯文本摘要(用于 <description>)
|
||||
String plain = textSummary(absHtml, 180);
|
||||
|
||||
// 5) enclosure(首图,已绝对化)
|
||||
String enclosure = firstImage(p.getContent());
|
||||
if (enclosure == null) {
|
||||
// 如果 Markdown 没有图,尝试从渲染后的 HTML 再抓一次
|
||||
enclosure = firstImage(absHtml);
|
||||
}
|
||||
if (enclosure != null) {
|
||||
enclosure = absolutifyUrl(enclosure, base);
|
||||
}
|
||||
|
||||
sb.append("<item>");
|
||||
elem(sb, "title", cdata(nullSafe(p.getTitle())));
|
||||
elem(sb, "link", link);
|
||||
sb.append("<guid isPermaLink=\"true\">").append(link).append("</guid>");
|
||||
elem(sb, "pubDate", toRfc1123Gmt(p.getCreatedAt().atZone(ZoneId.systemDefault())));
|
||||
// 摘要
|
||||
elem(sb, "description", cdata(plain));
|
||||
// 全文(HTML)
|
||||
sb.append("<content:encoded><![CDATA[").append(absHtml).append("]]></content:encoded>");
|
||||
// 首图 enclosure(图片类型)
|
||||
if (enclosure != null) {
|
||||
sb.append("<enclosure url=\"").append(escapeXml(enclosure)).append("\" type=\"")
|
||||
.append(getMimeType(enclosure)).append("\" />");
|
||||
}
|
||||
sb.append("</item>");
|
||||
}
|
||||
|
||||
sb.append("</channel></rss>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/* ===================== Markdown → HTML ===================== */
|
||||
|
||||
private static String renderMarkdown(String md) {
|
||||
if (md == null || md.isEmpty()) return "";
|
||||
return MD_RENDERER.render(MD_PARSER.parse(md));
|
||||
}
|
||||
|
||||
/* ===================== Sanitize & 绝对化 ===================== */
|
||||
|
||||
private static String sanitizeHtml(String html) {
|
||||
if (html == null) return "";
|
||||
Safelist wl = Safelist.relaxed()
|
||||
.addTags("pre", "code", "figure", "figcaption", "picture", "source",
|
||||
"table","thead","tbody","tr","th","td","h1","h2","h3","h4","h5","h6")
|
||||
.addAttributes("a", "href", "title", "target", "rel")
|
||||
.addAttributes("img", "src", "alt", "title", "width", "height")
|
||||
.addAttributes("source", "srcset", "type", "media")
|
||||
.addAttributes("code", "class")
|
||||
.addAttributes("pre", "class")
|
||||
.addProtocols("a", "href", "http", "https", "mailto")
|
||||
.addProtocols("img", "src", "http", "https", "data")
|
||||
.addProtocols("source", "srcset", "http", "https");
|
||||
// 清除所有 on* 事件、style(避免阅读器环境差异)
|
||||
return Jsoup.clean(html, wl);
|
||||
}
|
||||
|
||||
private static String absolutifyHtml(String html, String baseUrl) {
|
||||
if (html == null || html.isEmpty()) return "";
|
||||
Document doc = Jsoup.parseBodyFragment(html, baseUrl);
|
||||
// a[href]
|
||||
for (Element a : doc.select("a[href]")) {
|
||||
String href = a.attr("href");
|
||||
String abs = absolutifyUrl(href, baseUrl);
|
||||
a.attr("href", abs);
|
||||
// 强制外链安全属性
|
||||
a.attr("rel", "noopener noreferrer nofollow");
|
||||
a.attr("target", "_blank");
|
||||
}
|
||||
// img[src]
|
||||
for (Element img : doc.select("img[src]")) {
|
||||
String src = img.attr("src");
|
||||
String abs = absolutifyUrl(src, baseUrl);
|
||||
img.attr("src", abs);
|
||||
}
|
||||
// source[srcset] (picture/webp)
|
||||
for (Element s : doc.select("source[srcset]")) {
|
||||
String srcset = s.attr("srcset");
|
||||
s.attr("srcset", absolutifySrcset(srcset, baseUrl));
|
||||
}
|
||||
return doc.body().html();
|
||||
}
|
||||
|
||||
private static String absolutifyUrl(String url, String baseUrl) {
|
||||
if (url == null || url.isEmpty()) return url;
|
||||
String u = url.trim();
|
||||
if (u.startsWith("//")) {
|
||||
return "https:" + u;
|
||||
}
|
||||
if (u.startsWith("#")) {
|
||||
// 保留页面内锚点:拼接到首页(也可拼接到当前帖子的 link,但此处无上下文)
|
||||
return baseUrl + "/" + u;
|
||||
}
|
||||
try {
|
||||
URI base = URI.create(ensureTrailingSlash(baseUrl));
|
||||
URI abs = base.resolve(u);
|
||||
return abs.toString();
|
||||
} catch (Exception e) {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
private static String absolutifySrcset(String srcset, String baseUrl) {
|
||||
if (srcset == null || srcset.isEmpty()) return srcset;
|
||||
String[] parts = srcset.split(",");
|
||||
List<String> out = new ArrayList<>(parts.length);
|
||||
for (String part : parts) {
|
||||
String p = part.trim();
|
||||
if (p.isEmpty()) continue;
|
||||
String[] seg = p.split("\\s+");
|
||||
String url = seg[0];
|
||||
String size = seg.length > 1 ? seg[1] : "";
|
||||
out.add(absolutifyUrl(url, baseUrl) + (size.isEmpty() ? "" : " " + size));
|
||||
}
|
||||
return String.join(", ", out);
|
||||
}
|
||||
|
||||
/* ===================== 摘要 & enclosure ===================== */
|
||||
|
||||
private static String textSummary(String html, int maxLen) {
|
||||
if (html == null) return "";
|
||||
String text = Jsoup.parse(html).text().replaceAll("\\s+", " ").trim();
|
||||
if (text.length() <= maxLen) return text;
|
||||
return text.substring(0, maxLen) + "…";
|
||||
}
|
||||
|
||||
private String firstImage(String content) {
|
||||
if (content == null) return null;
|
||||
Matcher m = MD_IMAGE.matcher(content);
|
||||
if (m.find()) return m.group(1);
|
||||
m = HTML_IMAGE.matcher(content);
|
||||
if (m.find()) return m.group(1);
|
||||
// 再从纯 HTML 里解析一次(如果传入的是渲染后的)
|
||||
try {
|
||||
Document doc = Jsoup.parse(content);
|
||||
Element img = doc.selectFirst("img[src]");
|
||||
if (img != null) return img.attr("src");
|
||||
} catch (Exception ignored) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getMimeType(String url) {
|
||||
String lower = url == null ? "" : url.toLowerCase(Locale.ROOT);
|
||||
if (lower.endsWith(".png")) return "image/png";
|
||||
if (lower.endsWith(".gif")) return "image/gif";
|
||||
if (lower.endsWith(".webp")) return "image/webp";
|
||||
if (lower.endsWith(".svg")) return "image/svg+xml";
|
||||
if (lower.endsWith(".avif")) return "image/avif";
|
||||
if (lower.endsWith(".jpg") || lower.endsWith(".jpeg")) return "image/jpeg";
|
||||
// 默认兜底
|
||||
return "image/jpeg";
|
||||
}
|
||||
|
||||
/* ===================== 时间/字符串/XML ===================== */
|
||||
|
||||
private static String toRfc1123Gmt(ZonedDateTime zdt) {
|
||||
return zdt.withZoneSameInstant(ZoneId.of("GMT")).format(RFC1123);
|
||||
}
|
||||
|
||||
private static String cdata(String s) {
|
||||
if (s == null) return "<![CDATA[]]>";
|
||||
// 防止出现 "]]>" 终止标记破坏 CDATA
|
||||
return "<![CDATA[" + s.replace("]]>", "]]]]><![CDATA[>") + "]]>";
|
||||
}
|
||||
|
||||
private static void elem(StringBuilder sb, String name, String value) {
|
||||
sb.append('<').append(name).append('>').append(value).append("</").append(name).append('>');
|
||||
}
|
||||
|
||||
private static String escapeXml(String s) {
|
||||
if (s == null) return "";
|
||||
return s.replace("&", "&").replace("<", "<").replace(">", ">")
|
||||
.replace("\"", """).replace("'", "'");
|
||||
}
|
||||
|
||||
private static String trimTrailingSlash(String s) {
|
||||
if (s == null) return "";
|
||||
return s.endsWith("/") ? s.substring(0, s.length() - 1) : s;
|
||||
}
|
||||
|
||||
private static String ensureTrailingSlash(String s) {
|
||||
if (s == null || s.isEmpty()) return "/";
|
||||
return s.endsWith("/") ? s : s + "/";
|
||||
}
|
||||
|
||||
private static String nullSafe(String s) { return s == null ? "" : s; }
|
||||
}
|
||||
@@ -31,5 +31,6 @@ public class PostSummaryDto {
|
||||
private int pointReward;
|
||||
private PostType type;
|
||||
private LotteryDto lottery;
|
||||
private boolean rssExcluded;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ public class PostMapper {
|
||||
dto.setCommentCount(commentService.countComments(post.getId()));
|
||||
dto.setStatus(post.getStatus());
|
||||
dto.setPinnedAt(post.getPinnedAt());
|
||||
dto.setRssExcluded(post.getRssExcluded() == null || post.getRssExcluded());
|
||||
|
||||
List<ReactionDto> reactions = reactionService.getReactionsForPost(post.getId())
|
||||
.stream()
|
||||
|
||||
@@ -67,4 +67,6 @@ public class Post {
|
||||
@Column
|
||||
private LocalDateTime pinnedAt;
|
||||
|
||||
@Column(nullable = true)
|
||||
private Boolean rssExcluded = true;
|
||||
}
|
||||
|
||||
@@ -106,4 +106,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {
|
||||
"WHERE p.createdAt >= :start AND p.createdAt < :end GROUP BY d ORDER BY d")
|
||||
java.util.List<Object[]> countDailyRange(@Param("start") LocalDateTime start,
|
||||
@Param("end") LocalDateTime end);
|
||||
|
||||
List<Post> findByStatusAndRssExcludedFalseOrderByCreatedAtDesc(PostStatus status, Pageable pageable);
|
||||
}
|
||||
|
||||
@@ -132,6 +132,23 @@ public class PostService {
|
||||
this.publishMode = publishMode;
|
||||
}
|
||||
|
||||
public List<Post> listLatestRssPosts(int limit) {
|
||||
Pageable pageable = PageRequest.of(0, limit, Sort.by(Sort.Direction.DESC, "createdAt"));
|
||||
return postRepository.findByStatusAndRssExcludedFalseOrderByCreatedAtDesc(PostStatus.PUBLISHED, pageable);
|
||||
}
|
||||
|
||||
public Post excludeFromRss(Long id) {
|
||||
Post post = postRepository.findById(id).orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||
post.setRssExcluded(true);
|
||||
return postRepository.save(post);
|
||||
}
|
||||
|
||||
public Post includeInRss(Long id) {
|
||||
Post post = postRepository.findById(id).orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||
post.setRssExcluded(false);
|
||||
return postRepository.save(post);
|
||||
}
|
||||
|
||||
public Post createPost(String username,
|
||||
Long categoryId,
|
||||
String title,
|
||||
|
||||
@@ -77,7 +77,7 @@ public class UserService {
|
||||
public User registerWithInvite(String username, String email, String password) {
|
||||
User user = register(username, email, password, "", com.openisle.model.RegisterMode.DIRECT);
|
||||
user.setVerified(true);
|
||||
user.setVerificationCode(null);
|
||||
user.setVerificationCode(genCode());
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE posts ADD COLUMN rss_excluded BOOLEAN NOT NULL DEFAULT 0;
|
||||
@@ -16,11 +16,11 @@
|
||||
<div class="info-content-header-left">
|
||||
<span class="user-name">{{ comment.userName }}</span>
|
||||
<i class="fas fa-medal medal-icon"></i>
|
||||
<router-link
|
||||
<NuxtLink
|
||||
v-if="comment.medal"
|
||||
class="medal-name"
|
||||
:to="`/users/${comment.userId}?tab=achievements`"
|
||||
>{{ getMedalTitle(comment.medal) }}</router-link
|
||||
>{{ getMedalTitle(comment.medal) }}</NuxtLink
|
||||
>
|
||||
<i v-if="comment.pinned" class="fas fa-thumbtack pin-icon"></i>
|
||||
<span v-if="level >= 2">
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
/>
|
||||
<NotificationSettingPopup :visible="showNotificationPopup" @close="closeNotificationPopup" />
|
||||
<MedalPopup :visible="showMedalPopup" :medals="newMedals" @close="closeMedalPopup" />
|
||||
|
||||
<ActivityPopup
|
||||
:visible="showInviteCodePopup"
|
||||
:icon="inviteCodeIcon"
|
||||
text="邀请码活动开始了,速来参与大伙们🔥🔥🔥"
|
||||
@close="closeInviteCodePopup"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -21,7 +28,10 @@ const config = useRuntimeConfig()
|
||||
const API_BASE_URL = config.public.apiBaseUrl
|
||||
|
||||
const showMilkTeaPopup = ref(false)
|
||||
const showInviteCodePopup = ref(false)
|
||||
const milkTeaIcon = ref('')
|
||||
const inviteCodeIcon = ref('')
|
||||
|
||||
const showNotificationPopup = ref(false)
|
||||
const showMedalPopup = ref(false)
|
||||
const newMedals = ref([])
|
||||
@@ -30,6 +40,9 @@ onMounted(async () => {
|
||||
await checkMilkTeaActivity()
|
||||
if (showMilkTeaPopup.value) return
|
||||
|
||||
await checkInviteCodeActivity()
|
||||
if (showInviteCodePopup.value) return
|
||||
|
||||
await checkNotificationSetting()
|
||||
if (showNotificationPopup.value) return
|
||||
|
||||
@@ -53,12 +66,38 @@ const checkMilkTeaActivity = async () => {
|
||||
// ignore network errors
|
||||
}
|
||||
}
|
||||
|
||||
const checkInviteCodeActivity = async () => {
|
||||
if (!process.client) return
|
||||
if (localStorage.getItem('inviteCodeActivityPopupShown')) return
|
||||
try {
|
||||
const res = await fetch(`${API_BASE_URL}/api/activities`)
|
||||
if (res.ok) {
|
||||
const list = await res.json()
|
||||
const a = list.find((i) => i.type === 'INVITE_POINTS' && !i.ended)
|
||||
if (a) {
|
||||
inviteCodeIcon.value = a.icon
|
||||
showInviteCodePopup.value = true
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore network errors
|
||||
}
|
||||
}
|
||||
|
||||
const closeInviteCodePopup = () => {
|
||||
if (!process.client) return
|
||||
localStorage.setItem('inviteCodeActivityPopupShown', 'true')
|
||||
showInviteCodePopup.value = false
|
||||
}
|
||||
|
||||
const closeMilkTeaPopup = () => {
|
||||
if (!process.client) return
|
||||
localStorage.setItem('milkTeaActivityPopupShown', 'true')
|
||||
showMilkTeaPopup.value = false
|
||||
checkNotificationSetting()
|
||||
}
|
||||
|
||||
const checkNotificationSetting = async () => {
|
||||
if (!process.client) return
|
||||
if (!authState.loggedIn) return
|
||||
|
||||
@@ -29,6 +29,18 @@
|
||||
<i :class="iconClass"></i>
|
||||
</div>
|
||||
|
||||
<div v-if="!isMobile" class="invite_text" @click="copyInviteLink">
|
||||
<i class="fas fa-copy"></i>
|
||||
邀请
|
||||
<i v-if="isCopying" class="fas fa-spinner fa-spin"></i>
|
||||
</div>
|
||||
|
||||
<ToolTip content="复制RSS链接" placement="bottom">
|
||||
<div class="rss-icon" @click="copyRssLink">
|
||||
<i class="fas fa-rss"></i>
|
||||
</div>
|
||||
</ToolTip>
|
||||
|
||||
<ToolTip v-if="!isMobile && isLogin" content="发帖" placement="bottom">
|
||||
<div class="new-post-icon" @click="goToNewPost">
|
||||
<i class="fas fa-edit"></i>
|
||||
@@ -66,6 +78,11 @@ import { authState, clearToken, loadCurrentUser } from '~/utils/auth'
|
||||
import { fetchUnreadCount, notificationState } from '~/utils/notification'
|
||||
import { useIsMobile } from '~/utils/screen'
|
||||
import { themeState, cycleTheme, ThemeMode } from '~/utils/theme'
|
||||
import { toast } from '~/main'
|
||||
import { getToken } from '~/utils/auth'
|
||||
const config = useRuntimeConfig()
|
||||
const API_BASE_URL = config.public.apiBaseUrl
|
||||
const WEBSITE_BASE_URL = config.public.websiteBaseUrl
|
||||
|
||||
const props = defineProps({
|
||||
showMenuBtn: {
|
||||
@@ -82,6 +99,7 @@ const showSearch = ref(false)
|
||||
const searchDropdown = ref(null)
|
||||
const userMenu = ref(null)
|
||||
const menuBtn = ref(null)
|
||||
const isCopying = ref(false)
|
||||
|
||||
const search = () => {
|
||||
showSearch.value = true
|
||||
@@ -100,6 +118,41 @@ const goToLogin = () => {
|
||||
const goToSettings = () => {
|
||||
navigateTo('/settings', { replace: true })
|
||||
}
|
||||
|
||||
const copyInviteLink = async () => {
|
||||
isCopying.value = true
|
||||
const token = getToken()
|
||||
if (!token) {
|
||||
toast.error('请先登录')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await fetch(`${API_BASE_URL}/api/invite/generate`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
const inviteLink = data.token ? `${WEBSITE_BASE_URL}/signup?invite_token=${data.token}` : ''
|
||||
await navigator.clipboard.writeText(inviteLink)
|
||||
toast.success('邀请链接已复制')
|
||||
} else {
|
||||
const data = await res.json().catch(() => ({}))
|
||||
toast.error(data.error || '生成邀请链接失败')
|
||||
}
|
||||
} catch (e) {
|
||||
toast.error('生成邀请链接失败')
|
||||
} finally {
|
||||
isCopying.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const copyRssLink = async () => {
|
||||
const rssLink = `${API_BASE_URL}/api/rss`
|
||||
await navigator.clipboard.writeText(rssLink)
|
||||
toast.success('RSS链接已复制')
|
||||
}
|
||||
|
||||
const goToProfile = async () => {
|
||||
if (!authState.loggedIn) {
|
||||
navigateTo('/login', { replace: true })
|
||||
@@ -224,7 +277,7 @@ onMounted(async () => {
|
||||
margin-left: auto;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
gap: 30px;
|
||||
}
|
||||
|
||||
.auth-btns {
|
||||
@@ -315,11 +368,41 @@ onMounted(async () => {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.invite_text {
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.invite_text:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.rss-icon,
|
||||
.new-post-icon {
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.rss-icon {
|
||||
animation: rss-glow 2s 3;
|
||||
}
|
||||
|
||||
@keyframes rss-glow {
|
||||
0% {
|
||||
text-shadow: 0 0 0px var(--primary-color);
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
text-shadow: 0 0 12px var(--primary-color);
|
||||
opacity: 0.8;
|
||||
}
|
||||
100% {
|
||||
text-shadow: 0 0 0px var(--primary-color);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
.header-content {
|
||||
padding-left: 15px;
|
||||
@@ -336,5 +419,9 @@ onMounted(async () => {
|
||||
.logo-text {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.header-content-right {
|
||||
gap: 15px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
<span class="invite-code-description-title-text">邀请规则说明</span>
|
||||
</div>
|
||||
<div class="invite-code-description-content">
|
||||
<p>邀请好友注册并登录,每次可以获得500积分</p>
|
||||
<p>⚠️邀请好友注册并登录,每次可以获得500积分🎉🎉🎉</p>
|
||||
<p>邀请链接的有效期为1个月</p>
|
||||
<p>每一个邀请链接的邀请人数上限为3人</p>
|
||||
<p>通过邀请链接注册,无需注册审核</p>
|
||||
<p>每人每天仅能生产3个邀请链接</p>
|
||||
<p>每人每天仅能生产1个邀请链接</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="inviteLink" class="invite-code-link-content">
|
||||
<p>
|
||||
<p class="invite-code-link-content-text">
|
||||
邀请链接:{{ inviteLink }}
|
||||
<span @click="copyLink"><i class="fas fa-copy copy-icon"></i></span>
|
||||
</p>
|
||||
@@ -48,9 +48,9 @@ onMounted(async () => {
|
||||
isLoadingUser.value = true
|
||||
user.value = await fetchCurrentUser()
|
||||
isLoadingUser.value = false
|
||||
if (user.value) {
|
||||
await fetchInvite(false)
|
||||
}
|
||||
// if (user.value) {
|
||||
// await fetchInvite(false)
|
||||
// }
|
||||
})
|
||||
|
||||
const fetchInvite = async (showToast = true) => {
|
||||
@@ -171,6 +171,10 @@ const copyLink = async () => {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.invite-code-link-content-text {
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.copy-icon {
|
||||
cursor: pointer;
|
||||
margin-left: 5px;
|
||||
|
||||
@@ -12,7 +12,6 @@ export default defineNuxtConfig({
|
||||
twitterClientId: process.env.NUXT_PUBLIC_TWITTER_CLIENT_ID || '',
|
||||
},
|
||||
},
|
||||
// 确保 Vditor 样式在 global.css 覆盖前加载
|
||||
css: ['vditor/dist/index.css', '~/assets/fonts.css', '~/assets/global.css'],
|
||||
app: {
|
||||
pageTransition: { name: 'page', mode: 'out-in' },
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="not-found-page">
|
||||
<h1>404 - 页面不存在</h1>
|
||||
<p>你访问的页面不存在或已被删除</p>
|
||||
<router-link to="/">返回首页</router-link>
|
||||
<NuxtLink to="/">返回首页</NuxtLink>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
.activity-card-normal-right {
|
||||
width: calc(100% - 150px);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
|
||||
@@ -66,61 +66,61 @@
|
||||
<span class="notif-type">
|
||||
<template v-if="item.type === 'COMMENT_REPLY' && item.parentComment">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.comment.author.id}`"
|
||||
>{{ item.comment.author.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
对我的评论
|
||||
<span>
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}#comment-${item.parentComment.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.parentComment.content, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</span>
|
||||
回复了
|
||||
<span>
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}#comment-${item.comment.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.content, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</span>
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'COMMENT_REPLY' && !item.parentComment">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.comment.author.id}`"
|
||||
>{{ item.comment.author.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
对我的文章
|
||||
<span>
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</span>
|
||||
回复了
|
||||
<span>
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}#comment-${item.comment.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.content, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</span>
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
@@ -140,310 +140,310 @@
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<span class="notif-user">{{ item.fromUser.username }} </span> 对我的文章
|
||||
<span>
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</span>
|
||||
进行了表态
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'REACTION' && item.comment">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.fromUser.id}`"
|
||||
>{{ item.fromUser.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
对我的评论
|
||||
<span>
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}#comment-${item.comment.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.content, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</span>
|
||||
进行了表态
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'POST_VIEWED'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.fromUser.id}`"
|
||||
>
|
||||
{{ item.fromUser.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
查看了您的帖子
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'LOTTERY_WIN'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
恭喜你在抽奖贴
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
中获奖
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'LOTTERY_DRAW'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
您的抽奖贴
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
已开奖
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'POST_UPDATED'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
您关注的帖子
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
下面有新评论
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}#comment-${item.comment.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.content, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'USER_ACTIVITY' && item.parentComment">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
你关注的
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.comment.author.id}`"
|
||||
>
|
||||
{{ item.comment.author.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
在 对评论
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}#comment-${item.parentComment.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.parentComment.content, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
回复了
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}#comment-${item.comment.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.content, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'USER_ACTIVITY'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
你关注的
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.comment.author.id}`"
|
||||
>
|
||||
{{ item.comment.author.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
在文章
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
下面评论了
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}#comment-${item.comment.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.content, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'MENTION' && item.comment">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.fromUser.id}`"
|
||||
>
|
||||
{{ item.fromUser.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
在评论中提到了你:
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}#comment-${item.comment.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.content, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'MENTION'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.fromUser.id}`"
|
||||
>
|
||||
{{ item.fromUser.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
在帖子
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
中提到了你
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'USER_FOLLOWED'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.fromUser.id}`"
|
||||
>
|
||||
{{ item.fromUser.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
开始关注你了
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'USER_UNFOLLOWED'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.fromUser.id}`"
|
||||
>
|
||||
{{ item.fromUser.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
取消关注你了
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'FOLLOWED_POST'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
你关注的
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.fromUser.id}`"
|
||||
>
|
||||
{{ item.fromUser.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
发布了文章
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'POST_SUBSCRIBED'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.fromUser.id}`"
|
||||
>
|
||||
{{ item.fromUser.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
订阅了你的文章
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'POST_UNSUBSCRIBED'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.fromUser.id}`"
|
||||
>
|
||||
{{ item.fromUser.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
取消订阅了你的文章
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'POST_REVIEW_REQUEST' && item.fromUser">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/users/${item.fromUser.id}`"
|
||||
>
|
||||
{{ item.fromUser.username }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
发布了帖子
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
,请审核
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'POST_REVIEW_REQUEST'">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
您发布的帖子
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
已提交审核
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
@@ -472,26 +472,26 @@
|
||||
<template v-else-if="item.type === 'POST_REVIEWED' && item.approved">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
您发布的帖子
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
已审核通过
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'POST_REVIEWED' && item.approved === false">
|
||||
<NotificationContainer :item="item" :markRead="markRead">
|
||||
您发布的帖子
|
||||
<router-link
|
||||
<NuxtLink
|
||||
class="notif-content-text"
|
||||
@click="markRead(item.id)"
|
||||
:to="`/posts/${item.post.id}`"
|
||||
>
|
||||
{{ stripMarkdownLength(item.post.title, 100) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
已被管理员拒绝
|
||||
</NotificationContainer>
|
||||
</template>
|
||||
|
||||
@@ -63,6 +63,7 @@ const pointRules = [
|
||||
'评论:每天前四条评论可获 10 积分,你的帖子被评论也可获 10 积分',
|
||||
'帖子被点赞:每次 10 积分',
|
||||
'评论被点赞:每次 10 积分',
|
||||
'邀请好友加入可获得 500 积分/次,注意需要使用邀请链接注册',
|
||||
]
|
||||
|
||||
const goods = ref([])
|
||||
@@ -128,7 +129,7 @@ const submitRedeem = async () => {
|
||||
|
||||
<style scoped>
|
||||
.point-mall-page {
|
||||
padding-left: 20px;
|
||||
padding: 0 20px;
|
||||
max-width: var(--page-max-width);
|
||||
background-color: var(--background-color);
|
||||
margin: 0 auto;
|
||||
|
||||
@@ -52,11 +52,11 @@
|
||||
<div class="user-name">
|
||||
{{ author.username }}
|
||||
<i class="fas fa-medal medal-icon"></i>
|
||||
<router-link
|
||||
<NuxtLink
|
||||
v-if="author.displayMedal"
|
||||
class="user-medal"
|
||||
:to="`/users/${author.id}?tab=achievements`"
|
||||
>{{ getMedalTitle(author.displayMedal) }}</router-link
|
||||
>{{ getMedalTitle(author.displayMedal) }}</NuxtLink
|
||||
>
|
||||
</div>
|
||||
<div class="post-time">{{ postTime }}</div>
|
||||
@@ -68,11 +68,11 @@
|
||||
<div class="user-name">
|
||||
{{ author.username }}
|
||||
<i class="fas fa-medal medal-icon"></i>
|
||||
<router-link
|
||||
<NuxtLink
|
||||
v-if="author.displayMedal"
|
||||
class="user-medal"
|
||||
:to="`/users/${author.id}?tab=achievements`"
|
||||
>{{ getMedalTitle(author.displayMedal) }}</router-link
|
||||
>{{ getMedalTitle(author.displayMedal) }}</NuxtLink
|
||||
>
|
||||
</div>
|
||||
<div class="post-time">{{ postTime }}</div>
|
||||
@@ -268,6 +268,7 @@ const postReactions = ref([])
|
||||
const comments = ref([])
|
||||
const status = ref('PUBLISHED')
|
||||
const pinnedAt = ref(null)
|
||||
const rssExcluded = ref(false)
|
||||
const isWaitingPostingComment = ref(false)
|
||||
const postTime = ref('')
|
||||
const postItems = ref([])
|
||||
@@ -356,6 +357,11 @@ const articleMenuItems = computed(() => {
|
||||
} else {
|
||||
items.push({ text: '置顶', onClick: () => pinPost() })
|
||||
}
|
||||
if (rssExcluded.value) {
|
||||
items.push({ text: 'rss推荐', onClick: () => includeRss() })
|
||||
} else {
|
||||
items.push({ text: '取消rss推荐', onClick: () => excludeRss() })
|
||||
}
|
||||
}
|
||||
if (isAdmin.value && status.value === 'PENDING') {
|
||||
items.push({ text: '通过审核', onClick: () => approvePost() })
|
||||
@@ -480,6 +486,7 @@ watchEffect(() => {
|
||||
subscribed.value = !!data.subscribed
|
||||
status.value = data.status
|
||||
pinnedAt.value = data.pinnedAt
|
||||
rssExcluded.value = data.rssExcluded
|
||||
postTime.value = TimeManager.format(data.createdAt)
|
||||
lottery.value = data.lottery || null
|
||||
if (lottery.value && lottery.value.endTime) startCountdown()
|
||||
@@ -645,6 +652,36 @@ const unpinPost = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const excludeRss = async () => {
|
||||
const token = getToken()
|
||||
if (!token) return
|
||||
const res = await fetch(`${API_BASE_URL}/api/admin/posts/${postId}/rss-exclude`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (res.ok) {
|
||||
rssExcluded.value = true
|
||||
toast.success('已标记为rss不推荐')
|
||||
} else {
|
||||
toast.error('操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
const includeRss = async () => {
|
||||
const token = getToken()
|
||||
if (!token) return
|
||||
const res = await fetch(`${API_BASE_URL}/api/admin/posts/${postId}/rss-include`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (res.ok) {
|
||||
rssExcluded.value = false
|
||||
toast.success('已标记为rss推荐')
|
||||
} else {
|
||||
toast.error('操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
const editPost = () => {
|
||||
navigateTo(`/posts/${postId}/edit`, { replace: true })
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ import { discordAuthorize } from '~/utils/discord'
|
||||
import { githubAuthorize } from '~/utils/github'
|
||||
import { googleAuthorize } from '~/utils/google'
|
||||
import { twitterAuthorize } from '~/utils/twitter'
|
||||
import { loadCurrentUser, setToken } from '~/utils/auth'
|
||||
|
||||
const route = useRoute()
|
||||
const config = useRuntimeConfig()
|
||||
@@ -160,6 +161,7 @@ const sendVerification = async () => {
|
||||
username: username.value,
|
||||
email: email.value,
|
||||
password: password.value,
|
||||
inviteToken: inviteToken.value,
|
||||
}),
|
||||
})
|
||||
isWaitingForEmailSent.value = false
|
||||
@@ -192,11 +194,18 @@ const verifyCode = async () => {
|
||||
})
|
||||
const data = await res.json()
|
||||
if (res.ok) {
|
||||
if (registerMode.value === 'WHITELIST') {
|
||||
navigateTo(`/signup-reason?token=${data.token}`, { replace: true })
|
||||
} else {
|
||||
toast.success('注册成功,请登录')
|
||||
navigateTo('/login', { replace: true })
|
||||
if (data.reason_code === 'VERIFIED_AND_APPROVED') {
|
||||
toast.success('注册成功')
|
||||
setToken(data.token)
|
||||
loadCurrentUser()
|
||||
navigateTo('/', { replace: true })
|
||||
} else if (data.reason_code === 'VERIFIED') {
|
||||
if (registerMode.value === 'WHITELIST') {
|
||||
navigateTo(`/signup-reason?token=${data.token}`, { replace: true })
|
||||
} else {
|
||||
toast.success('注册成功,请登录')
|
||||
navigateTo('/login', { replace: true })
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast.error(data.error || '注册失败')
|
||||
|
||||
@@ -130,26 +130,26 @@
|
||||
<BaseTimeline :items="hotReplies">
|
||||
<template #item="{ item }">
|
||||
在
|
||||
<router-link :to="`/posts/${item.comment.post.id}`" class="timeline-link">
|
||||
<NuxtLink :to="`/posts/${item.comment.post.id}`" class="timeline-link">
|
||||
{{ item.comment.post.title }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
<template v-if="item.comment.parentComment">
|
||||
下对
|
||||
<router-link
|
||||
<NuxtLink
|
||||
:to="`/posts/${item.comment.post.id}#comment-${item.comment.parentComment.id}`"
|
||||
class="timeline-link"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.parentComment.content, 200) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
回复了
|
||||
</template>
|
||||
<template v-else> 下评论了 </template>
|
||||
<router-link
|
||||
<NuxtLink
|
||||
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
|
||||
class="timeline-link"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.content, 200) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
<div class="timeline-date">
|
||||
{{ formatDate(item.comment.createdAt) }}
|
||||
</div>
|
||||
@@ -165,9 +165,9 @@
|
||||
<div class="summary-content" v-if="hotPosts.length > 0">
|
||||
<BaseTimeline :items="hotPosts">
|
||||
<template #item="{ item }">
|
||||
<router-link :to="`/posts/${item.post.id}`" class="timeline-link">
|
||||
<NuxtLink :to="`/posts/${item.post.id}`" class="timeline-link">
|
||||
{{ item.post.title }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
<div class="timeline-snippet">
|
||||
{{ stripMarkdown(item.post.snippet) }}
|
||||
</div>
|
||||
@@ -236,44 +236,44 @@
|
||||
<template #item="{ item }">
|
||||
<template v-if="item.type === 'post'">
|
||||
发布了文章
|
||||
<router-link :to="`/posts/${item.post.id}`" class="timeline-link">
|
||||
<NuxtLink :to="`/posts/${item.post.id}`" class="timeline-link">
|
||||
{{ item.post.title }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'comment'">
|
||||
在
|
||||
<router-link :to="`/posts/${item.comment.post.id}`" class="timeline-link">
|
||||
<NuxtLink :to="`/posts/${item.comment.post.id}`" class="timeline-link">
|
||||
{{ item.comment.post.title }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
下评论了
|
||||
<router-link
|
||||
<NuxtLink
|
||||
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
|
||||
class="timeline-link"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.content, 200) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'reply'">
|
||||
在
|
||||
<router-link :to="`/posts/${item.comment.post.id}`" class="timeline-link">
|
||||
<NuxtLink :to="`/posts/${item.comment.post.id}`" class="timeline-link">
|
||||
{{ item.comment.post.title }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
下对
|
||||
<router-link
|
||||
<NuxtLink
|
||||
:to="`/posts/${item.comment.post.id}#comment-${item.comment.parentComment.id}`"
|
||||
class="timeline-link"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.parentComment.content, 200) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
回复了
|
||||
<router-link
|
||||
<NuxtLink
|
||||
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
|
||||
class="timeline-link"
|
||||
>
|
||||
{{ stripMarkdownLength(item.comment.content, 200) }}
|
||||
</router-link>
|
||||
</NuxtLink>
|
||||
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'tag'">
|
||||
|
||||
@@ -2,6 +2,7 @@ import Vditor from 'vditor'
|
||||
import { getToken, authState } from './auth'
|
||||
import { searchUsers, fetchFollowings, fetchAdmins } from './user'
|
||||
import { tiebaEmoji } from './tiebaEmoji'
|
||||
import '~/assets/global.css'
|
||||
|
||||
export function getEditorTheme() {
|
||||
return document.documentElement.dataset.theme === 'dark' ? 'dark' : 'classic'
|
||||
|
||||
Reference in New Issue
Block a user