Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/util/db-schema/name-rules.ts
Views: 687
/* Checks that name satisfies the following constraints1Inspired by -- https://github.com/isiahmeadows/github-limits23Each function checks the basic rules, but NOT for uniqueness,4which requires a DB query.56If a rule fails, throws an Error.78The URL schema is910https://cocalc.com/[account name]/[project name]/[shared path name]1112We are only using these URL's for the share server.13We only use such a URL if all segments are specified.1415NOTE: at some point we considered using these url's for more than just16the share server, and maybe when some segments aren't specified. If we17did that, we have to have a lot more constraints on the segments, e.g.,18we can't allow "files" for the shared path name. But we are NOT doing19that.20*/2122import { is_valid_uuid_string } from "../misc";2324export function isReserved(name: string): boolean {25return RESERVED.has(name.toLowerCase());26}2728/*29Account name:30- between 1 and 39 characters31- doesn't start with a -32- only includes the characters 0-9,a-z,A-Z,-33- Don't allow uuid's.34- cannot include consecutive hyphens35*/36export function checkAccountName(name: string) {37if (name.length < 1) {38throw Error("name must have at least 1 character");39}40if (name.length > 39) {41throw Error("name must have at most 39 characters");42}43if (is_valid_uuid_string(name)) {44throw Error("name must not be a v4 UUID");45}46if (name.includes("--")) {47throw Error("name must not contain consecutive hyphens");48}49if (!/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i.test(name)) {50throw Error(51"name must contain only a-z,A-Z,0-9, or -, and not start with hyphen.",52);53}54// Check for reserved names.55if (isReserved(name)) {56throw Error(`username "${name}" is reserved -- not available`);57}58}5960/*61Project name:6263- Max length: 100 characters64- All characters must be either a hyphen (-), a period (.), or alphanumeric65- Unique amongst projects with given owner (that's a separate db query)66*/67export function checkProjectName(name: string) {68if (name.length < 1) {69throw Error("name must have at least 1 character");70}71if (name.length > 100) {72throw Error("name must have at most 100 characters");73}74if (!/^[\.a-z\d](?:[\.a-z\d]|-(?=[\.a-z\d])){0,99}$/i.test(name)) {75throw Error(76"name must contain only a-z,A-Z,0-9, . or -, and not start with hyphen or have spaces.",77);78}79}8081/*82Public path name:8384- Max length: 100 characters85- All characters must be either a hyphen (-), a period (.), or alphanumeric86- Unique amongst public paths in a given project (a separate db query)87*/8889export function checkPublicPathName(name: string) {90if (name.length < 1) {91throw Error("name must have at least 1 character");92}93if (name.length > 100) {94throw Error("name must have at most 100 characters");95}96if (!/^[\.a-z\d](?:[\.a-z\d]|-(?=[\.a-z\d])){0,99}$/i.test(name)) {97throw Error(98"name must contain only a-z,A-Z,0-9, . or -, and not start with hyphen or have spaces.",99);100}101}102103// Combined words from what we use, https://www.quora.com/How-do-sites-prevent-vanity-URLs-from-colliding-with-future-features104// and https://github.com/Mottie/github-reserved-names/blob/master/reserved-names.json and105// https://github.com/Mottie/github-reserved-names and random other things.106// If you add more and want to clean this up in the console, this may be helpful:107// Array.from(RESERVED).sort().join(' ')108const RESERVED = new Set(109`\1100111400112401113402114403115404116405117406118407119408120409121410122411123412124413125414126415127416128417129418130419131420132421133422134423135424136425137426138427139428140429141430142431143500144501145502146503147504148505149506150507151508152509153510154511155about156access157account158accounts159action160actions161activate162activities163activity164ad165add166address167adm168admin169administration170administrator171ads172adult173advertising174advisories175affiliate176affiliates177ajax178alive179all180alpha181analysis182analytics183android184anon185anonymous186any187api188app189apps190archive191archives192article193articles194asct195ask196asset197assets198atom199attributes200auth201authentication202avatar203backup204balancer-manager205banner206banners207beta208better209billing210bin211blob212blobs213blog214blogs215board216book217bookmark218bot219bots220bounty221branches222bug223business224businesses225c226cache227cadastro228calendar229call230campaign231cancel232captcha233career234careers235cart236case-studies237categories238category239cdn240central241certification242cgi243cgi-bin244changelog245chat246check247checking248checkout249cla250client251cliente252clients253cloud254cocalc255cocksucker256code257codereview258collection259collections260comercial261comment262comments263commit264commits265communities266community267companies268company269compare270compras271compute272config273configuration274connect275contact276contact_us277contact-us278contactus279contest280contribute281contributing282cookbook283cookies284corp285coupon286coupons287create288crm289css290cunt291customer292customer-stories293customers294customize295dashboard296dashboards297data298db299default300delete301demo302design303designer304destroy305dev306devel307develop308developer309developers310diagram311diary312dict313dictionary314die315diff316dir317direct_messages318directory319discover320discussions321dist322doc323docs324documentation325domain326download327downloads328downtime329ecommerce330edit331editor332editors333edu334education335336embed337employment338empty339end340enterprise341entries342entry343error344errors345eval346event347events348exit349explore350351faq352favorite353favorites354feature355featured356features357feed358feedback359feeds360file361files362first363fixtures364flash365fleet366fleets367flog368follow369followers370following371font372fonts373forgot374forked375form376forum377forums378founder379free380friend381friends382ftp383fuck384gadget385gadgets386game387games388garage389get390ghost391gift392gifts393gist394gists395github396github.com397gitlab398gitlab.com399grafana400graph401graphs402group403groups404guest405guests406guide407guides408help409help-wanted410home411homepage412hooks413host414hosting415hostmaster416hostname417hovercards418howto419hpg420html421http422httpd423https424hub425i426iamges427icon428icons429id430idea431ideas432identity433image434images435imap436img437inbox438include439includes440index441indice442individual443info444information445inquiry446447integration448interfaces449intern450internal451intranet452introduction453invalid-email-address454investors455invitations456invite457invoice458ipad459iphone460irc461is462issue463issues464it465item466items467java468javascript469job470jobs471join472journal473journals474js475json476jump477knowledgebase478lab479labs480language481languages482last483launch484layouts485ldap-status486learn487legal488library489license490licenses491link492links493linux494list495listings496lists497log498log_in499log_out500log-in501log-out502login503logos504logout505logs506m507mac508509mail1510mail2511mail3512mail4513mail5514mailer515mailing516maintenance517malware518man519manager520manual521map522maps523marketing524marketplace525master526me527media528member529members530mention531mentioned532mentioning533mentions534message535messages536messenger537metrics538microblog539microblogs540migrating541milestones542mine543mirrors544mis545misc546mob547mobile548module549modules550monitor551motherfucker552movie553movies554mp3555msg556msn557music558musicas559mx560my561mysql562name563named564nan565navi566navigation567nbextensions568net569network570new571news572newsletter573nick574nickname575nocodb576node577nodes578none579nonprofit580nonprofits581notes582notices583noticias584notification585notifications586notify587ns588ns1589ns10590ns2591ns3592ns4593ns5594ns6595ns7596ns8597ns9598null599oauth600oauth_clients601offer602offers603office604official605old606online607open-source608openid609operator610order611orders612organisations613organization614organizations615orgs616overview617owner618owners619page620pager621pages622panel623partners624password625password-reset626payment627payments628perl629personal630phone631photo632photoalbum633photos634php635phpmyadmin636phppgadmin637phpredisadmin638pic639pics640ping641piss642plan643plans644plugin645plugins646policies647policy648poll649polls650pop651pop3652popular653popularity654portal655post656postfix657postmaster658posts659pr660premium661press662price663pricing664primus665privacy666privacy_policy667privacy-policy668privacypolicy669private670processes671product672products673professional674profile675profiles676project677projects678prometheus679promo680pub681public682pulls683purchase684purchases685purpose686put687python688query689random690ranking691raw692rdf693rdfs694read695readme696recent697recommendations698recruit699recruitment700redeem701register702registration703release704releases705remove706render707replies708reply709report710reports711repositories712repository713req714request715requests716reset717resources718restore719revert720roc721root722rss723ruby724rule725sag726sagemath727sagemathinc728sale729sales730sample731samples732save733save-net-neutrality734saved735school736scraping737script738scripts739search740secure741security742self743send744server745server-info746server-status747service748services749session750sessions751setting752settings753setup754share755shareholders756shit757shop758show759showcases760sign_in761sign_up762sign-in763sign-up764signin765signout766signup767site768sitemap769sites770smartphone771smtp772snapshots773software774soporte775source776spam777spec778special779sponsors780sql781src782ssh783ssl784ssladmin785ssladministrator786sslwebmaster787sso788staff789stage790staging791star792starred793stars794start795stat796state797static798statistics799stats800status801statuses802storage803store804stores805stories806style807styleguide808stylesheet809stylesheets810subdomain811subscribe812subscriptions813suggest814suggestion815suggestions816suporte817support818survey819surveys820suspended821svn822swf823sys824sysadmin825sysadministrator826system827tablet828tablets829tag830talk831talks832task833tasks834teach835teacher836teachers837teaching838team839teams840tech841telnet842template843templates844ten845term846terms847terms_of_service848terms-of-service849termsofservice850test851test1852test2853test3854teste855testimonials856testing857tests858theme859themes860thread861threads862timeline863timetravel864tits865tmp866todo867token868tool869tools870top871topic872topics873tos874tour875train876training877translations878tree879trending880trends881try882tutorial883tutorials884tux885tv886887twittr888undef889unfollow890unsubscribe891update892updates893upload894uploads895url896usage897user898username899users900usuario901vendas902ver903version904video905videos906visitor907visualization908voucher909vouchers910w911watch912watching913weather914web915webapp916webhook917webhooks918webmail919webmaster920website921websites922welcome923widget924widgets925wiki926win927windows928word929work930works931works-with932workshop933ww934wws935www936www0937www1938www2939www3940www4941www5942www6943www7944www8945www9946wwws947wwww948xfn949xml950xmpp951xpg952xxx953yaml954year955yml956you957yourdomain958yourname959yoursite960yourusername`.split("\n"),961);962963// for testing only964if (process.env["NODE_DEV"] === "TEST") {965exports.RESERVED = RESERVED;966}967968969