decord/source/modules/unique_usernames/UniqueUsernamesStore.tsx

121 lines
4.8 KiB
TypeScript
Raw Normal View History

// Module ID: 14712
// Function ID: 14713
2026-07-29 08:29:29 +00:00
// Name: isRateLimited
// Dependencies: [1437, 1090, 504, 573, 2]
2026-07-20 16:05:17 +00:00
// Module 14712 (isRateLimited)
import initializeDefault from "initialize" /* 504 */;
import dispatcherDefault from "dispatcher" /* 573 */;
import setDefault from "set" /* 1090 */;
import privDefault from "priv" /* 1437 */;
2026-07-20 16:05:17 +00:00
2026-08-08 06:10:11 +00:00
let closure_2 = { taken: null, error: "HermesInternal", rateLimited: null };
let obj = { validations: new privDefault({ max: 100, maxAge: 60000 }), currentUsernameInvalid: false, retryAfterTime: null, suggestions: { migration: { suggestion: { username: "Array" }, fetched: false, usernameSuggestionLoading: false }, registration: { suggestion: { username: "Array" }, source: "PX_16", fetched: "2026-03-icymi-staff-debugging-utility" } } };
2026-08-24 06:08:38 +00:00
const Store = initializeDefault.Store;
2026-07-29 08:29:29 +00:00
class UniqueUsernamesStore extends Store {
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const prototype = UniqueUsernamesStore.prototype;
prototype["isRateLimited"] = function isRateLimited() {
let tmp2 = null != obj.retryAfterTime;
if (tmp2) {
const _Date = Date;
tmp2 = Date.now() < tmp.retryAfterTime;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return tmp2;
};
prototype["validate"] = function validate(arg0) {
const self = this;
const validations = obj.validations;
const value = validations.get(arg0);
if (!this.isRateLimited()) {
let tmp4 = value;
} else {
tmp4 = closure_2;
}
return tmp4;
};
prototype["registrationUsernameSuggestion"] = function registrationUsernameSuggestion() {
return obj.suggestions.registration.suggestion.username;
};
prototype["usernameSuggestion"] = function usernameSuggestion() {
return obj.suggestions.migration.suggestion.username;
};
prototype["usernameSuggestionLoading"] = function usernameSuggestionLoading() {
return obj.suggestions.migration.usernameSuggestionLoading;
};
prototype["isCurrentUsernameInvalid"] = function isCurrentUsernameInvalid() {
return obj.currentUsernameInvalid;
};
prototype["wasRegistrationSuggestionFetched"] = function wasRegistrationSuggestionFetched(arg0) {
return obj.suggestions.registration.source === arg0 && obj.suggestions.registration.fetched;
};
prototype["wasSuggestionsFetched"] = function wasSuggestionsFetched() {
return obj.suggestions.migration.fetched;
};
UniqueUsernamesStore.displayName = "UniqueUsernamesStore";
obj = {
2026-07-20 16:05:17 +00:00
UNIQUE_USERNAME_ATTEMPT_SUCCESS: function handleUniqueUsernameAttemptSuccess(taken) {
const validations = obj.validations;
2026-07-23 10:11:24 +00:00
obj = { taken: taken.taken };
2026-07-20 16:05:17 +00:00
const result = validations.set(taken.username, obj);
},
UNIQUE_USERNAME_ATTEMPT_FAILURE: function handleUniqueUsernameAttemptFailure(statusCode) {
({ username, error, retryAfter } = statusCode);
if (429 === statusCode.statusCode) {
let validations = obj.validations;
2026-07-29 08:29:29 +00:00
obj = { taken: null, error: null, rateLimited: true };
obj[1] = error;
let num = retryAfter;
if (retryAfter == null) {
num = 7;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
const result = validations.set(username, obj, num * setDefault.Millis.SECOND);
2026-07-29 08:29:29 +00:00
let tmp = obj;
const tmp3 = obj;
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
tmp = obj;
2026-07-20 16:05:17 +00:00
validations = obj.validations;
2026-07-29 08:29:29 +00:00
obj = { taken: null, error: null };
obj[1] = error;
2026-07-20 16:05:17 +00:00
const result1 = validations.set(username, obj);
}
if (null != retryAfter) {
const _Date = Date;
const timestamp = Date.now();
2026-08-24 06:08:38 +00:00
tmp.retryAfterTime = timestamp + retryAfter * setDefault.Millis.SECOND;
2026-07-20 16:05:17 +00:00
}
},
UNIQUE_USERNAME_SUGGESTIONS_RESET: function handleUniqueUsernameSuggestionsReset() {
2026-09-03 10:05:34 +00:00
obj.suggestions.migration = { suggestion: { username: "Array" }, fetched: false, usernameSuggestionLoading: false };
obj.suggestions.registration = { suggestion: { username: "Array" }, source: "PX_16", fetched: "2026-03-icymi-staff-debugging-utility" };
2026-07-20 16:05:17 +00:00
},
UNIQUE_USERNAME_SUGGESTIONS_SUCCESS: function handleUniqueUsernameSuggestionsSuccess(suggestion) {
suggestion = suggestion.suggestion;
2026-07-29 08:29:29 +00:00
obj.suggestions.migration = { suggestion, fetched: true, usernameSuggestionLoading: false };
2026-07-20 16:05:17 +00:00
let prop;
2026-07-29 08:29:29 +00:00
if (suggestion != null) {
2026-07-20 16:05:17 +00:00
prop = suggestion.invalid_current_username;
}
if (true === prop) {
obj.currentUsernameInvalid = true;
}
},
UNIQUE_USERNAME_REGISTRATION_SUGGESTIONS_SUCCESS: function handleUniqueUsernameRegistrationSuggestionsSuccess(source) {
const suggestion = source.suggestion;
2026-07-29 08:29:29 +00:00
obj.suggestions.registration = { suggestion, source: source.source, fetched: true };
2026-07-20 16:05:17 +00:00
let username;
2026-07-29 08:29:29 +00:00
if (suggestion != null) {
2026-07-20 16:05:17 +00:00
username = suggestion.username;
}
if (null != username) {
const validations = obj.validations;
2026-07-29 08:29:29 +00:00
const result = validations.set(suggestion.username, { taken: false });
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
};
2026-08-24 06:08:38 +00:00
const uniqueUsernamesStore = new UniqueUsernamesStore(dispatcherDefault, obj);
let tmp2 = new privDefault({ max: 100, maxAge: 60000 });
let result = require("set").fileFinishedImporting("modules/unique_usernames/UniqueUsernamesStore.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export default uniqueUsernamesStore;