Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7165246
Add CI workflow for lbbs_dev branch
ytht Nov 11, 2025
dd4045b
设置不合并yml文件
ytht Nov 11, 2025
c0345b7
Add lbbs_dev branch to CI workflow
ytht Nov 11, 2025
f7a34bf
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 14, 2025
927ad82
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 16, 2025
649b302
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 17, 2025
eed0fed
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 17, 2025
919364e
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 17, 2025
3c58c8b
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 17, 2025
e576a07
增加 文章收录/移出文摘区 功能
ytht Nov 17, 2025
4eb5a15
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 19, 2025
d9e6bc0
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 20, 2025
e703e1e
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 21, 2025
fdbc07e
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 22, 2025
4633091
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 23, 2025
87535cc
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 23, 2025
8a27ea7
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 23, 2025
27dd4df
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 24, 2025
0dea966
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 26, 2025
9a31e02
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 27, 2025
608f8fb
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 27, 2025
c6299a4
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 28, 2025
5125da3
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 30, 2025
a8f548b
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 2, 2025
66b558e
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 2, 2025
b391b41
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 4, 2025
f4b1df2
优化 文章收录/移出文摘区 功能
ytht Dec 4, 2025
fb8aca0
Merge branch 'lbbs_dev' of https://github.com/ytht/lbbs into lbbs_dev
ytht Dec 4, 2025
f97b252
优化 文章收录/移出文摘区 功能
ytht Dec 7, 2025
59cc0ba
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 17, 2025
769de21
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 19, 2025
049da93
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 20, 2025
aacdade
优化 文章收录/移出文摘区 功能
ytht Dec 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.github/workflows/*.yml merge=notMerge
10 changes: 7 additions & 3 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ name: Makefile CI

on:
push:
branches: [ "main" ]
branches:
- "main"
- "lbbs_dev"
pull_request:
branches: [ "main" ]

branches:
- "main"
- "lbbs_dev"

jobs:
build:

Expand Down
7 changes: 7 additions & 0 deletions include/article_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
#ifndef _ARTICLE_OP_H_
#define _ARTICLE_OP_H_

#include <section_list.h>
#include <stdint.h>

enum bbs_article_op_type_t
{
BBS_article_set_excerption = 'E',
BBS_article_unset_excerption = 'O',
};
extern int display_article_meta(int32_t aid);
extern int article_exc_set(SECTION_LIST *p_section,int32_t aid, int8_t is_exc);

#endif //_ARTICLE_OP_H_
253 changes: 253 additions & 0 deletions src/article_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@

#include "article_op.h"
#include "bbs.h"
#include "common.h"
#include "database.h"
#include "io.h"
#include "log.h"
#include "screen.h"
#include "user_priv.h"
#include <stdlib.h>
#include <string.h>

enum ret_msg_len_t
{
ret_msg_len = 20,
};

int display_article_meta(int32_t aid)
{
Expand All @@ -26,3 +37,245 @@ int display_article_meta(int32_t aid)

return 0;
}

int article_exc_set(SECTION_LIST *p_section, int32_t aid, int8_t is_exc)
{
MYSQL *db = NULL;
MYSQL_RES *rs = NULL;
MYSQL_ROW row;
char sql[SQL_BUFFER_LEN];
int ret = 0;
int uid = 0;
int tid = 0;
int sid = 0;
int8_t transship = 0;
int8_t excerption = 0;
int8_t set_exc = !is_exc;
char ret_msg[ret_msg_len] = "";
int section_set_exc_ret = 0;

if (p_section == NULL)
{
log_error("NULL pointer error\n");
ret = -1;
goto cleanup;
}

sid = p_section->sid;

db = db_open();
if (db == NULL)
{
log_error("db_open() error: %s\n", mysql_error(db));
ret = -1;
goto cleanup;
}
// Begin transaction
if (mysql_query(db, "SET autocommit=0") != 0)
{
log_error("SET autocommit=0 error: %s\n", mysql_error(db));
ret = -1;
goto cleanup;
}
if (mysql_query(db, "BEGIN") != 0)
{
log_error("Begin transaction error: %s\n", mysql_error(db));
ret = -1;
goto cleanup;
}

snprintf(sql, sizeof(sql),
"SELECT UID, TID, SID, transship, excerption FROM bbs WHERE visible and AID=%d FOR UPDATE",
aid);
if (mysql_query(db, sql) != 0)
{
log_error("Query bbs error: %s\n", mysql_error(db));
ret = -2;
goto cleanup;
}
if ((rs = mysql_store_result(db)) == NULL)
{
log_error("Get article data failed\n");
ret = -2;
goto cleanup;
}
if ((row = mysql_fetch_row(rs)))
{
if (sid != atoi(row[2]))
{
log_error("sid error: sid = %d, row[2]= %s, aid = %d\n", sid, row[2], aid);
ret = -2;
goto cleanup;
}
uid = atoi(row[0]);
tid = atoi(row[1]);
transship = (int8_t)atoi(row[3]);
excerption = (int8_t)atoi(row[4]);
}
else
{
log_error("mysql_fetch_row() error: %s\n", mysql_error(db));
ret = -2;
goto cleanup;
}
mysql_free_result(rs);
rs = NULL;

// Check if already set
if (set_exc == excerption)
{
snprintf(ret_msg, sizeof(ret_msg), "已%s文摘区", set_exc ? "收录" : "移出");
ret = 1;
goto cleanup;
}

// Update article(s)
snprintf(sql, sizeof(sql),
"UPDATE bbs SET excerption = %d WHERE AID=%d",
set_exc, aid);
if (mysql_query(db, sql) != 0)
{
log_error("Update article set error: %s\n", mysql_error(db));
ret = -1;
goto cleanup;
}

// Clear gen_ex if unset excerption
if (set_exc == 0)
{
snprintf(sql, sizeof(sql),
"UPDATE bbs SET gen_ex = 0, static = 0 WHERE AID=%d OR TID =%d",
aid, aid);

if (mysql_query(db, sql) != 0)
{
log_error("Clear gen_ex error: %s\n", mysql_error(db));
ret = -1;
goto cleanup;
}

// Delete ex_dir path if head of thread
if (tid == 0)
{
snprintf(sql, sizeof(sql),
"DELETE FROM ex_file WHERE AID = %d",
aid);

if (mysql_query(db, sql) != 0)
{
log_error("Delete ex_dir error: %s\n", mysql_error(db));
ret = -1;
goto cleanup;
}
}
}

// Change UID of attachments
snprintf(sql, sizeof(sql),
"UPDATE upload_file SET UID = %d WHERE ref_AID = %d AND deleted = 0",
set_exc ? 0 : uid, aid);
if (mysql_query(db, sql) != 0)
{
log_error("Change UID error: %s\n", mysql_error(db));
ret = -1;
goto cleanup;
}

// Modify exp
if (checkpriv(&BBS_priv, sid, S_GETEXP)) // Except in test section
{
snprintf(sql, sizeof(sql),
"UPDATE user_pubinfo SET exp = exp + %d WHERE UID = %d",
(set_exc ? 1 : -1) * (tid == 0 ? (transship ? 20 : 50) : 10), uid);

if (mysql_query(db, sql) != 0)
{
log_error("Update exp error: %s\n", mysql_error(db));
ret = -1;
goto cleanup;
}
}

// Add log
snprintf(sql, sizeof(sql),
"INSERT INTO bbs_article_op(AID, UID, type, op_dt, op_ip)"
"VALUES(%d, %d, '%c', NOW(), '%s')",
aid, BBS_priv.uid, set_exc ? BBS_article_set_excerption : BBS_article_unset_excerption, hostaddr_client);

if (mysql_query(db, sql) != 0)
{
log_error("Add log error: %s\n", mysql_error(db));
ret = -1;
goto cleanup;
}

if (section_list_rw_lock(p_section) != 0)
{
log_error("section_list_rw_lock error on section %d\n", sid);
ret = -1;
goto cleanup;
}
section_set_exc_ret = section_list_set_article_excerption(p_section, aid, set_exc);
if (section_set_exc_ret == 0)
{
ret = 1;
goto cleanup;
}
else if (section_set_exc_ret < 0)
{
log_error("section_list_set_article_excerption error sid = %d, aid= %d, set_exc= %d\n", sid, aid, set_exc);
ret = -1;
goto cleanup;
}
if (section_list_rw_unlock(p_section) != 0)
{
log_error("section_list_rw_unlock error on section %d\n", sid);
ret = -1;
goto cleanup;
}

// Commit transaction
if (mysql_query(db, "COMMIT") != 0)
{
if (section_list_rw_lock(p_section) != 0)
{
log_error("section_list_rw_lock error on section %d\n", sid);
ret = -1;
goto cleanup;
}
section_set_exc_ret = section_list_set_article_excerption(p_section, aid, !set_exc);
if (section_set_exc_ret == 0)
{
ret = -1;
goto cleanup;
}
else if (section_set_exc_ret < 0)
{
log_error("section_list_set_article_excerption error sid = %d, aid= %d, set_exc= %d\n", sid, aid, !set_exc);
ret = -1;
goto cleanup;
}
if (section_list_rw_unlock(p_section) != 0)
{
log_error("section_list_rw_unlock error on section %d\n", sid);
ret = -1;
goto cleanup;
}

log_error("Commit transaction error: %s\n", mysql_error(db));
ret = -1;
goto cleanup;
}

mysql_close(db);
db = NULL;

snprintf(ret_msg, sizeof(ret_msg), "已%s文摘区", set_exc ? "收录" : "移出");
ret = 1; // Success

cleanup:
mysql_free_result(rs);
mysql_close(db);
// press_any_key_ex(ret_msg, 3);
return ret;
}
19 changes: 19 additions & 0 deletions src/section_list_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum select_cmd_t
QUERY_USER,
SET_FAVOR_ARTICLE,
UNSET_FAVOR_ARTICLE,
SET_EXCERPTION_ARTICLE,
FIRST_TOPIC_ARTICLE,
LAST_TOPIC_ARTICLE,
LAST_SECTION_ARTICLE,
Expand Down Expand Up @@ -341,6 +342,12 @@ static enum select_cmd_t section_list_select(int total_page, int item_count, int
return UNSET_FAVOR_ARTICLE;
}
break;
case 'm':
if (item_count > 0)
{
return SET_EXCERPTION_ARTICLE;
}
break;
case KEY_HOME:
*p_page_id = 0;
case 'P':
Expand Down Expand Up @@ -1093,6 +1100,18 @@ int section_list_display(const char *sname, int32_t aid)
p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
}
break;
case SET_EXCERPTION_ARTICLE:
if (!checkpriv(&BBS_priv, p_section->sid, S_POST) || !checkpriv(&BBS_priv, p_section->sid, S_MAN_S))
{
break;
}
ret = article_exc_set(p_section, p_articles[selected_index]->aid, p_articles[selected_index]->excerption);
if (ret < 0)
{
log_error("article_exc_set(aid=%d, excerption=%d) error\n",
p_articles[selected_index]->aid, p_articles[selected_index]->excerption);
}
break;
case FIRST_TOPIC_ARTICLE:
case LAST_TOPIC_ARTICLE:
page_id_cur = page_id;
Expand Down