mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: vacuum database in setting (#694)
* feat: vacuum database in setting * update * update * update * update
This commit is contained in:
@ -148,4 +148,26 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
g.POST("/system/vacuum", func(c echo.Context) error {
|
||||||
|
ctx := c.Request().Context()
|
||||||
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
||||||
|
if !ok {
|
||||||
|
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||||
|
}
|
||||||
|
user, err := s.Store.FindUser(ctx, &api.UserFind{
|
||||||
|
ID: &userID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user").SetInternal(err)
|
||||||
|
}
|
||||||
|
if user == nil || user.Role != api.Host {
|
||||||
|
return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")
|
||||||
|
}
|
||||||
|
if err := s.Store.Vacuum(ctx); err != nil {
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to vacuum database").SetInternal(err)
|
||||||
|
}
|
||||||
|
c.Response().WriteHeader(http.StatusOK)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,23 @@ const SystemSection = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleVacuumBtnClick = async () => {
|
||||||
|
try {
|
||||||
|
await api.vacuumDatabase();
|
||||||
|
const { data: status } = (await api.getSystemStatus()).data;
|
||||||
|
setState({
|
||||||
|
dbSize: status.dbSize,
|
||||||
|
allowSignUp: status.allowSignUp,
|
||||||
|
additionalStyle: status.additionalStyle,
|
||||||
|
additionalScript: status.additionalScript,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
toastHelper.success("Succeed to vacuum database");
|
||||||
|
};
|
||||||
|
|
||||||
const handleSaveAdditionalStyle = async () => {
|
const handleSaveAdditionalStyle = async () => {
|
||||||
try {
|
try {
|
||||||
await api.upsertSystemSetting({
|
await api.upsertSystemSetting({
|
||||||
@ -96,9 +113,14 @@ const SystemSection = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="section-container system-section-container">
|
<div className="section-container system-section-container">
|
||||||
<p className="title-text">{t("common.basic")}</p>
|
<p className="title-text">{t("common.basic")}</p>
|
||||||
<p className="text-value">
|
<label className="form-label">
|
||||||
|
<span className="normal-text">
|
||||||
{t("setting.system-section.database-file-size")}: <span className="font-mono font-medium">{formatBytes(state.dbSize)}</span>
|
{t("setting.system-section.database-file-size")}: <span className="font-mono font-medium">{formatBytes(state.dbSize)}</span>
|
||||||
</p>
|
</span>
|
||||||
|
<Button size="sm" onClick={handleVacuumBtnClick}>
|
||||||
|
{t("common.vacuum")}
|
||||||
|
</Button>
|
||||||
|
</label>
|
||||||
<p className="title-text">{t("sidebar.setting")}</p>
|
<p className="title-text">{t("sidebar.setting")}</p>
|
||||||
<label className="form-label">
|
<label className="form-label">
|
||||||
<span className="normal-text">{t("setting.system-section.allow-user-signup")}</span>
|
<span className="normal-text">{t("setting.system-section.allow-user-signup")}</span>
|
||||||
|
@ -14,6 +14,10 @@ export function upsertSystemSetting(systemSetting: SystemSetting) {
|
|||||||
return axios.post<ResponseObject<SystemSetting>>("/api/system/setting", systemSetting);
|
return axios.post<ResponseObject<SystemSetting>>("/api/system/setting", systemSetting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function vacuumDatabase() {
|
||||||
|
return axios.post("/api/system/vacuum");
|
||||||
|
}
|
||||||
|
|
||||||
export function signin(username: string, password: string) {
|
export function signin(username: string, password: string) {
|
||||||
return axios.post<ResponseObject<User>>("/api/auth/signin", {
|
return axios.post<ResponseObject<User>>("/api/auth/signin", {
|
||||||
username,
|
username,
|
||||||
|
@ -45,7 +45,8 @@
|
|||||||
"fold": "Falten",
|
"fold": "Falten",
|
||||||
"expand": "Erweitern",
|
"expand": "Erweitern",
|
||||||
"image": "Bild",
|
"image": "Bild",
|
||||||
"link": "Link"
|
"link": "Link",
|
||||||
|
"vacuum": "Vacuum"
|
||||||
},
|
},
|
||||||
"slogan": "Eine quelloffene, selbst gehostete Sammlung an Memos zur Wissensverwaltung und Vernetzung.",
|
"slogan": "Eine quelloffene, selbst gehostete Sammlung an Memos zur Wissensverwaltung und Vernetzung.",
|
||||||
"auth": {
|
"auth": {
|
||||||
|
@ -45,7 +45,8 @@
|
|||||||
"fold": "Fold",
|
"fold": "Fold",
|
||||||
"expand": "Expand",
|
"expand": "Expand",
|
||||||
"image": "Image",
|
"image": "Image",
|
||||||
"link": "Link"
|
"link": "Link",
|
||||||
|
"vacuum": "Vacuum"
|
||||||
},
|
},
|
||||||
"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.",
|
"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.",
|
||||||
"auth": {
|
"auth": {
|
||||||
|
@ -45,7 +45,8 @@
|
|||||||
"fold": "Plier",
|
"fold": "Plier",
|
||||||
"expand": "Développer",
|
"expand": "Développer",
|
||||||
"image": "Image",
|
"image": "Image",
|
||||||
"link": "Link"
|
"link": "Link",
|
||||||
|
"vacuum": "Vacuum"
|
||||||
},
|
},
|
||||||
"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.",
|
"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.",
|
||||||
"auth": {
|
"auth": {
|
||||||
|
@ -41,7 +41,8 @@
|
|||||||
"changed": "gewijzigd",
|
"changed": "gewijzigd",
|
||||||
"update-on": "Update op",
|
"update-on": "Update op",
|
||||||
"fold": "Invouwen",
|
"fold": "Invouwen",
|
||||||
"expand": "Uitklappen"
|
"expand": "Uitklappen",
|
||||||
|
"vacuum": "Vacuum"
|
||||||
},
|
},
|
||||||
"slogan": "Een open-source, zelf-beheerd memo applicatie voor kennismanagement en collaboratie.",
|
"slogan": "Een open-source, zelf-beheerd memo applicatie voor kennismanagement en collaboratie.",
|
||||||
"auth": {
|
"auth": {
|
||||||
|
@ -45,7 +45,8 @@
|
|||||||
"fold": "Vik ihop",
|
"fold": "Vik ihop",
|
||||||
"expand": "Expandera",
|
"expand": "Expandera",
|
||||||
"image": "Bild",
|
"image": "Bild",
|
||||||
"link": "Länk"
|
"link": "Länk",
|
||||||
|
"vacuum": "Vacuum"
|
||||||
},
|
},
|
||||||
"slogan": "En öppen källkod, self-hosted antecknings hubb med kunskapshantering och socialisering",
|
"slogan": "En öppen källkod, self-hosted antecknings hubb med kunskapshantering och socialisering",
|
||||||
"auth": {
|
"auth": {
|
||||||
|
@ -45,7 +45,8 @@
|
|||||||
"fold": "Fold",
|
"fold": "Fold",
|
||||||
"expand": "Expand",
|
"expand": "Expand",
|
||||||
"image": "Image",
|
"image": "Image",
|
||||||
"link": "Link"
|
"link": "Link",
|
||||||
|
"vacuum": "Vacuum"
|
||||||
},
|
},
|
||||||
"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.",
|
"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.",
|
||||||
"auth": {
|
"auth": {
|
||||||
|
@ -45,7 +45,8 @@
|
|||||||
"fold": "折叠",
|
"fold": "折叠",
|
||||||
"expand": "展开",
|
"expand": "展开",
|
||||||
"image": "图片",
|
"image": "图片",
|
||||||
"link": "链接"
|
"link": "链接",
|
||||||
|
"vacuum": "清理"
|
||||||
},
|
},
|
||||||
"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.",
|
"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.",
|
||||||
"auth": {
|
"auth": {
|
||||||
|
Reference in New Issue
Block a user