mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-11 05:57:07 +03:00
Handle permission userinfo using new logic
This commit is contained in:
@@ -406,7 +406,10 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
)];
|
)];
|
||||||
|
|
||||||
for (const category of (this.props.categoryList ?? CompileConfig.categoryList)) {
|
for (const category of (this.props.categoryList ?? CompileConfig.categoryList)) {
|
||||||
if (category === "chapter" && !Config.config.canSubmitChapter) break;
|
// If permission not loaded, treat it like we have permission except chapter
|
||||||
|
const defaultBlockCategories = ["chapter"];
|
||||||
|
const permission = Config.config.permissions[category as Category];
|
||||||
|
if ((defaultBlockCategories.includes(category) || permission !== undefined) && !permission) continue;
|
||||||
|
|
||||||
elements.push(
|
elements.push(
|
||||||
<option value={category}
|
<option value={category}
|
||||||
|
|||||||
@@ -3,10 +3,14 @@ import * as invidiousList from "../ci/invidiouslist.json";
|
|||||||
import { Category, CategorySelection, CategorySkipOption, NoticeVisbilityMode, PreviewBarOption, SponsorTime, StorageChangesObject, Keybind, HashedValue, VideoID, SponsorHideType } from "./types";
|
import { Category, CategorySelection, CategorySkipOption, NoticeVisbilityMode, PreviewBarOption, SponsorTime, StorageChangesObject, Keybind, HashedValue, VideoID, SponsorHideType } from "./types";
|
||||||
import { keybindEquals } from "./utils/configUtils";
|
import { keybindEquals } from "./utils/configUtils";
|
||||||
|
|
||||||
|
export interface Permission {
|
||||||
|
canSubmit: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
interface SBConfig {
|
interface SBConfig {
|
||||||
userID: string,
|
userID: string,
|
||||||
isVip: boolean,
|
isVip: boolean,
|
||||||
canSubmitChapter: boolean,
|
permissions: Record<Category, Permission>,
|
||||||
/* Contains unsubmitted segments that the user has created. */
|
/* Contains unsubmitted segments that the user has created. */
|
||||||
unsubmittedSegments: Record<string, SponsorTime[]>,
|
unsubmittedSegments: Record<string, SponsorTime[]>,
|
||||||
defaultCategory: Category,
|
defaultCategory: Category,
|
||||||
@@ -133,7 +137,7 @@ const Config: SBObject = {
|
|||||||
syncDefaults: {
|
syncDefaults: {
|
||||||
userID: null,
|
userID: null,
|
||||||
isVip: false,
|
isVip: false,
|
||||||
canSubmitChapter: false,
|
permissions: {},
|
||||||
unsubmittedSegments: {},
|
unsubmittedSegments: {},
|
||||||
defaultCategory: "chooseACategory" as Category,
|
defaultCategory: "chooseACategory" as Category,
|
||||||
renderSegmentsAsChapters: true,
|
renderSegmentsAsChapters: true,
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
PageElements.showNoticeAgain.style.display = "unset";
|
PageElements.showNoticeAgain.style.display = "unset";
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&value=vip&value=canSubmitChapter&userID="
|
utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&value=vip&value=permissions&userID="
|
||||||
+ Config.config.userID, (res) => {
|
+ Config.config.userID, (res) => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
const userInfo = JSON.parse(res.responseText);
|
const userInfo = JSON.parse(res.responseText);
|
||||||
@@ -285,7 +285,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Config.config.isVip = userInfo.vip;
|
Config.config.isVip = userInfo.vip;
|
||||||
Config.config.canSubmitChapter = userInfo.canSubmitChapter;
|
Config.config.permissions = userInfo.permissions;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user