The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Routes.cs 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. using Microsoft.AspNetCore.Routing;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Teknik.Configuration;
  7. using Teknik.Utilities;
  8. namespace Teknik
  9. {
  10. public static class Routes
  11. {
  12. public static void BuildRoutes(this IRouteBuilder routes, Config config)
  13. {
  14. routes.BuildDefaultRoutes(config);
  15. routes.BuildAboutRoutes(config);
  16. routes.BuildAbuseRoutes(config);
  17. routes.BuildAdminRoutes(config);
  18. routes.BuildAPIRoutes(config);
  19. routes.BuildBlogRoutes(config);
  20. routes.BuildContactRoutes(config);
  21. routes.BuildDevRoutes(config);
  22. routes.BuildErrorRoutes(config);
  23. routes.BuildFAQRoutes(config);
  24. routes.BuildHelpRoutes(config);
  25. routes.BuildHomeRoutes(config);
  26. routes.BuildPasteRoutes(config);
  27. routes.BuildPodcastRoutes(config);
  28. routes.BuildPrivacyRoutes(config);
  29. routes.BuildRSSRoutes(config);
  30. routes.BuildShortenerRoutes(config);
  31. routes.BuildStatsRoutes(config);
  32. routes.BuildTOSRoutes(config);
  33. routes.BuildUploadRoutes(config);
  34. routes.BuildUserRoutes(config);
  35. routes.BuildVaultRoutes(config);
  36. }
  37. public static void BuildDefaultRoutes(this IRouteBuilder routes, Config config)
  38. {
  39. routes.MapSubdomainRoute(
  40. name: "Default.Favicon",
  41. domains: new List<string>() { config.Host, config.ShortenerConfig.ShortenerHost },
  42. subDomains: new List<string>() { "*" },
  43. template: "favicon.ico",
  44. defaults: new { area = "Default", controller = "Default", action = "Favicon" }
  45. );
  46. routes.MapSubdomainRoute(
  47. name: "Default.Logo",
  48. domains: new List<string>() { config.Host, config.ShortenerConfig.ShortenerHost },
  49. subDomains: new List<string>() { "*" },
  50. template: "logo.svg",
  51. defaults: new { area = "Default", controller = "Default", action = "Logo" }
  52. );
  53. routes.MapSubdomainRoute(
  54. name: "Default.Robots",
  55. domains: new List<string>() { config.Host, config.ShortenerConfig.ShortenerHost },
  56. subDomains: new List<string>() { "*" },
  57. template: "robots.txt",
  58. defaults: new { area = "Default", controller = "Default", action = "Robots" }
  59. );
  60. routes.MapSubdomainRoute(
  61. name: "Default.NotFound",
  62. domains: new List<string>() { config.Host, config.ShortenerConfig.ShortenerHost },
  63. subDomains: new List<string>() { "*" },
  64. template: "{url}",
  65. defaults: new { area = "Error", controller = "Error", action = "Http404" },
  66. constraints: new { url = "{*url}" }
  67. );
  68. }
  69. public static void BuildAboutRoutes(this IRouteBuilder routes, Config config)
  70. {
  71. routes.MapSubdomainRoute(
  72. name: "About.Index",
  73. domains: new List<string>() { config.Host },
  74. subDomains: new List<string>() { "about" },
  75. template: "",
  76. defaults: new { area = "About", controller = "About", action = "Index" }
  77. );
  78. }
  79. public static void BuildAbuseRoutes(this IRouteBuilder routes, Config config)
  80. {
  81. routes.MapSubdomainRoute(
  82. name: "Abuse.Index",
  83. domains: new List<string>() { config.Host },
  84. subDomains: new List<string>() { "abuse" },
  85. template: "",
  86. defaults: new { area = "Abuse", controller = "Abuse", action = "Index" }
  87. );
  88. }
  89. public static void BuildAdminRoutes(this IRouteBuilder routes, Config config)
  90. {
  91. routes.MapSubdomainRoute(
  92. name: "Admin.Dashboard",
  93. domains: new List<string>() { config.Host },
  94. subDomains: new List<string>() { "admin" },
  95. template: "",
  96. defaults: new { area = "Admin", controller = "Admin", action = "Dashboard" }
  97. );
  98. routes.MapSubdomainRoute(
  99. name: "Admin.UserSearch",
  100. domains: new List<string>() { config.Host },
  101. subDomains: new List<string>() { "admin" },
  102. template: "Search/Users",
  103. defaults: new { area = "Admin", controller = "Admin", action = "UserSearch" }
  104. );
  105. routes.MapSubdomainRoute(
  106. name: "Admin.UploadSearch",
  107. domains: new List<string>() { config.Host },
  108. subDomains: new List<string>() { "admin" },
  109. template: "Search/Uploads",
  110. defaults: new { area = "Admin", controller = "Admin", action = "UploadSearch" }
  111. );
  112. routes.MapSubdomainRoute(
  113. name: "Admin.UserInfo",
  114. domains: new List<string>() { config.Host },
  115. subDomains: new List<string>() { "admin" },
  116. template: "User/{username}",
  117. defaults: new { area = "Admin", controller = "Admin", action = "UserInfo", username = string.Empty }
  118. );
  119. routes.MapSubdomainRoute(
  120. name: "Admin.Action",
  121. domains: new List<string>() { config.Host },
  122. subDomains: new List<string>() { "admin" },
  123. template: "Action/{action}",
  124. defaults: new { area = "Admin", controller = "Admin", action = "Dashboard" }
  125. );
  126. }
  127. public static void BuildAPIRoutes(this IRouteBuilder routes, Config config)
  128. {
  129. routes.MapSubdomainRoute(
  130. name: "API.v1.Claims",
  131. domains: new List<string>() { config.Host },
  132. subDomains: new List<string>() { "api" },
  133. template: "v1/Claims",
  134. defaults: new { area = "API", controller = "AccountAPIv1", action = "GetClaims" }
  135. );
  136. routes.MapSubdomainRoute(
  137. name: "API.v1.Upload",
  138. domains: new List<string>() { config.Host },
  139. subDomains: new List<string>() { "api" },
  140. template: "v1/Upload",
  141. defaults: new { area = "API", controller = "UploadAPIv1", action = "Upload" }
  142. );
  143. routes.MapSubdomainRoute(
  144. name: "API.v1.Paste",
  145. domains: new List<string>() { config.Host },
  146. subDomains: new List<string>() { "api" },
  147. template: "v1/Paste",
  148. defaults: new { area = "API", controller = "PasteAPIv1", action = "Paste" }
  149. );
  150. routes.MapSubdomainRoute(
  151. name: "API.v1.Shorten",
  152. domains: new List<string>() { config.Host },
  153. subDomains: new List<string>() { "api" },
  154. template: "v1/Shorten",
  155. defaults: new { area = "API", controller = "ShortenAPIv1", action = "Shorten" }
  156. );
  157. routes.MapSubdomainRoute(
  158. name: "API.Index",
  159. domains: new List<string>() { config.Host },
  160. subDomains: new List<string>() { "api" },
  161. template: "",
  162. defaults: new { area = "API", controller = "API", action = "Index" }
  163. );
  164. }
  165. public static void BuildBlogRoutes(this IRouteBuilder routes, Config config)
  166. {
  167. routes.MapSubdomainRoute(
  168. name: "Blog.Blog",
  169. domains: new List<string>() { config.Host },
  170. subDomains: new List<string>() { "blog" },
  171. template: "{username}",
  172. defaults: new { area = "Blog", controller = "Blog", action = "Blog", username = string.Empty }
  173. );
  174. routes.MapSubdomainRoute(
  175. name: "Blog.New",
  176. domains: new List<string>() { config.Host },
  177. subDomains: new List<string>() { "blog" },
  178. template: "{username}/New",
  179. defaults: new { area = "Blog", controller = "Blog", action = "NewPost", username = string.Empty }
  180. );
  181. routes.MapSubdomainRoute(
  182. name: "Blog.Edit",
  183. domains: new List<string>() { config.Host },
  184. subDomains: new List<string>() { "blog" },
  185. template: "{username}/Edit/{id}",
  186. defaults: new { area = "Blog", controller = "Blog", action = "EditPost", username = string.Empty, id = -1 }
  187. );
  188. routes.MapSubdomainRoute(
  189. name: "Blog.Post",
  190. domains: new List<string>() { config.Host },
  191. subDomains: new List<string>() { "blog" },
  192. template: "{username}/p/{id}",
  193. defaults: new { area = "Blog", controller = "Blog", action = "Post", username = string.Empty, id = -1 }
  194. );
  195. routes.MapSubdomainRoute(
  196. name: "Blog.Action",
  197. domains: new List<string>() { config.Host },
  198. subDomains: new List<string>() { "blog" },
  199. template: "Action/{action}",
  200. defaults: new { area = "Blog", controller = "Blog", action = "Blog" }
  201. );
  202. }
  203. public static void BuildContactRoutes(this IRouteBuilder routes, Config config)
  204. {
  205. routes.MapSubdomainRoute(
  206. name: "Contact.Index",
  207. domains: new List<string>() { config.Host },
  208. subDomains: new List<string>() { "contact" },
  209. template: "",
  210. defaults: new { area = "Contact", controller = "Contact", action = "Index" }
  211. );
  212. routes.MapSubdomainRoute(
  213. name: "Contact.Action",
  214. domains: new List<string>() { config.Host },
  215. subDomains: new List<string>() { "contact" },
  216. template: "Action/{action}",
  217. defaults: new { area = "Contact", controller = "Contact", action = "Index" }
  218. );
  219. }
  220. public static void BuildDevRoutes(this IRouteBuilder routes, Config config)
  221. {
  222. routes.MapSubdomainRoute(
  223. name: "Dev.Index",
  224. domains: new List<string>() { config.Host },
  225. subDomains: new List<string>() { "dev" },
  226. template: "",
  227. defaults: new { area = "Dev", controller = "Dev", action = "Index" }
  228. );
  229. }
  230. public static void BuildErrorRoutes(this IRouteBuilder routes, Config config)
  231. {
  232. routes.MapSubdomainRoute(
  233. name: "Error.HttpError",
  234. domains: new List<string>() { config.Host },
  235. subDomains: new List<string>() { "error" },
  236. template: "{statusCode:int}",
  237. defaults: new { area = "Error", controller = "Error", action = "HttpError", statusCode = 500 }
  238. );
  239. routes.MapSubdomainRoute(
  240. name: "Error.Http401",
  241. domains: new List<string>() { config.Host },
  242. subDomains: new List<string>() { "error" },
  243. template: "401",
  244. defaults: new { area = "Error", controller = "Error", action = "Http401" }
  245. );
  246. routes.MapSubdomainRoute(
  247. name: "Error.Http403",
  248. domains: new List<string>() { config.Host },
  249. subDomains: new List<string>() { "error" },
  250. template: "403",
  251. defaults: new { area = "Error", controller = "Error", action = "Http403" }
  252. );
  253. routes.MapSubdomainRoute(
  254. name: "Error.Http404",
  255. domains: new List<string>() { config.Host },
  256. subDomains: new List<string>() { "error" },
  257. template: "404",
  258. defaults: new { area = "Error", controller = "Error", action = "Http404" }
  259. );
  260. routes.MapSubdomainRoute(
  261. name: "Error.Http500",
  262. domains: new List<string>() { config.Host },
  263. subDomains: new List<string>() { "error" },
  264. template: "500",
  265. defaults: new { area = "Error", controller = "Error", action = "Http500" }
  266. );
  267. routes.MapSubdomainRoute(
  268. name: "Error.Action",
  269. domains: new List<string>() { config.Host },
  270. subDomains: new List<string>() { "error" },
  271. template: "Action/{action}",
  272. defaults: new { area = "Error", controller = "Error", action = "HttpError" }
  273. );
  274. }
  275. public static void BuildFAQRoutes(this IRouteBuilder routes, Config config)
  276. {
  277. routes.MapSubdomainRoute(
  278. name: "FAQ.Index",
  279. domains: new List<string>() { config.Host },
  280. subDomains: new List<string>() { "faq" },
  281. template: "",
  282. defaults: new { area = "FAQ", controller = "FAQ", action = "Index" }
  283. );
  284. }
  285. public static void BuildHelpRoutes(this IRouteBuilder routes, Config config)
  286. {
  287. routes.MapSubdomainRoute(
  288. name: "Help.Index",
  289. domains: new List<string>() { config.Host },
  290. subDomains: new List<string>() { "help" },
  291. template: "",
  292. defaults: new { area = "Help", controller = "Help", action = "Index" }
  293. );
  294. routes.MapSubdomainRoute(
  295. name: "Help.API",
  296. domains: new List<string>() { config.Host },
  297. subDomains: new List<string>() { "help" },
  298. template: "API/{version?}/{service?}",
  299. defaults: new { area = "Help", controller = "Help", action = "API" }
  300. );
  301. routes.MapSubdomainRoute(
  302. name: "Help.Blog",
  303. domains: new List<string>() { config.Host },
  304. subDomains: new List<string>() { "help" },
  305. template: "Blog",
  306. defaults: new { area = "Help", controller = "Help", action = "Blog" }
  307. );
  308. routes.MapSubdomainRoute(
  309. name: "Help.Git",
  310. domains: new List<string>() { config.Host },
  311. subDomains: new List<string>() { "help" },
  312. template: "Git",
  313. defaults: new { area = "Help", controller = "Help", action = "Git" }
  314. );
  315. routes.MapSubdomainRoute(
  316. name: "Help.IRC",
  317. domains: new List<string>() { config.Host },
  318. subDomains: new List<string>() { "help" },
  319. template: "IRC",
  320. defaults: new { area = "Help", controller = "Help", action = "IRC" }
  321. );
  322. routes.MapSubdomainRoute(
  323. name: "Help.Mail",
  324. domains: new List<string>() { config.Host },
  325. subDomains: new List<string>() { "help" },
  326. template: "Mail",
  327. defaults: new { area = "Help", controller = "Help", action = "Mail" }
  328. );
  329. routes.MapSubdomainRoute(
  330. name: "Help.Markdown",
  331. domains: new List<string>() { config.Host },
  332. subDomains: new List<string>() { "help" },
  333. template: "Markdown",
  334. defaults: new { area = "Help", controller = "Help", action = "Markdown" }
  335. );
  336. routes.MapSubdomainRoute(
  337. name: "Help.Mumble",
  338. domains: new List<string>() { config.Host },
  339. subDomains: new List<string>() { "help" },
  340. template: "Mumble",
  341. defaults: new { area = "Help", controller = "Help", action = "Mumble" }
  342. );
  343. routes.MapSubdomainRoute(
  344. name: "Help.RSS",
  345. domains: new List<string>() { config.Host },
  346. subDomains: new List<string>() { "help" },
  347. template: "RSS",
  348. defaults: new { area = "Help", controller = "Help", action = "RSS" }
  349. );
  350. routes.MapSubdomainRoute(
  351. name: "Help.Tools",
  352. domains: new List<string>() { config.Host },
  353. subDomains: new List<string>() { "help" },
  354. template: "Tools",
  355. defaults: new { area = "Help", controller = "Help", action = "Tools" }
  356. );
  357. routes.MapSubdomainRoute(
  358. name: "Help.Upload",
  359. domains: new List<string>() { config.Host },
  360. subDomains: new List<string>() { "help" },
  361. template: "Upload",
  362. defaults: new { area = "Help", controller = "Help", action = "Upload" }
  363. );
  364. }
  365. public static void BuildHomeRoutes(this IRouteBuilder routes, Config config)
  366. {
  367. routes.MapSubdomainRoute(
  368. name: "Home.Index",
  369. domains: new List<string>() { config.Host },
  370. subDomains: new List<string>() { "www", string.Empty },
  371. template: "",
  372. defaults: new { area = "Home", controller = "Home", action = "Index" }
  373. );
  374. }
  375. public static void BuildPasteRoutes(this IRouteBuilder routes, Config config)
  376. {
  377. routes.MapSubdomainRoute(
  378. name: "Paste.Index",
  379. domains: new List<string>() { config.Host },
  380. subDomains: new List<string>() { "paste", "p" },
  381. template: "",
  382. defaults: new { area = "Paste", controller = "Paste", action = "Index" }
  383. );
  384. routes.MapSubdomainRoute(
  385. name: "Paste.Simple",
  386. domains: new List<string>() { config.Host },
  387. subDomains: new List<string>() { "paste", "p" },
  388. template: "Simple/{url}/{password?}",
  389. defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Simple" }
  390. );
  391. routes.MapSubdomainRoute(
  392. name: "Paste.Raw",
  393. domains: new List<string>() { config.Host },
  394. subDomains: new List<string>() { "paste", "p" },
  395. template: "Raw/{url}/{password?}",
  396. defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Raw" }
  397. );
  398. routes.MapSubdomainRoute(
  399. name: "Paste.Download",
  400. domains: new List<string>() { config.Host },
  401. subDomains: new List<string>() { "paste", "p" },
  402. template: "Download/{url}/{password?}",
  403. defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Download" }
  404. );
  405. routes.MapSubdomainRoute(
  406. name: "Paste.Edit",
  407. domains: new List<string>() { config.Host },
  408. subDomains: new List<string>() { "paste", "p" },
  409. template: "Edit/{url}/{password?}",
  410. defaults: new { area = "Paste", controller = "Paste", action = "Edit" }
  411. );
  412. routes.MapSubdomainRoute(
  413. name: "Paste.Delete",
  414. domains: new List<string>() { config.Host },
  415. subDomains: new List<string>() { "paste", "p" },
  416. template: "Delete",
  417. defaults: new { area = "Paste", controller = "Paste", action = "Delete" }
  418. );
  419. routes.MapSubdomainRoute(
  420. name: "Paste.Action",
  421. domains: new List<string>() { config.Host },
  422. subDomains: new List<string>() { "paste", "p" },
  423. template: "Action/{action}",
  424. defaults: new { area = "Paste", controller = "Paste", action = "Index" }
  425. );
  426. routes.MapSubdomainRoute(
  427. name: "Paste.View",
  428. domains: new List<string>() { config.Host },
  429. subDomains: new List<string>() { "paste", "p" },
  430. template: "{url}/{password?}",
  431. defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Full" }
  432. );
  433. }
  434. public static void BuildPodcastRoutes(this IRouteBuilder routes, Config config)
  435. {
  436. routes.MapSubdomainRoute(
  437. name: "Podcast.Index",
  438. domains: new List<string>() { config.Host },
  439. subDomains: new List<string>() { "podcast" },
  440. template: "",
  441. defaults: new { area = "Podcast", controller = "Podcast", action = "Index" }
  442. );
  443. routes.MapSubdomainRoute(
  444. name: "Podcast.View",
  445. domains: new List<string>() { config.Host },
  446. subDomains: new List<string>() { "podcast" },
  447. template: "ep/{episode}",
  448. defaults: new { area = "Podcast", controller = "Podcast", action = "View" }
  449. );
  450. routes.MapSubdomainRoute(
  451. name: "Podcast.Download",
  452. domains: new List<string>() { config.Host },
  453. subDomains: new List<string>() { "podcast" },
  454. template: "File/{episode}/{fileName}",
  455. defaults: new { area = "Podcast", controller = "Podcast", action = "Download" }
  456. );
  457. routes.MapSubdomainRoute(
  458. name: "Podcast.Action",
  459. domains: new List<string>() { config.Host },
  460. subDomains: new List<string>() { "podcast" },
  461. template: "Action/{action}",
  462. defaults: new { area = "Podcast", controller = "Podcast", action = "Index" }
  463. );
  464. }
  465. public static void BuildPrivacyRoutes(this IRouteBuilder routes, Config config)
  466. {
  467. routes.MapSubdomainRoute(
  468. name: "Privacy.Index",
  469. domains: new List<string>() { config.Host },
  470. subDomains: new List<string>() { "privacy" },
  471. template: "",
  472. defaults: new { area = "Privacy", controller = "Privacy", action = "Index" }
  473. );
  474. }
  475. public static void BuildRSSRoutes(this IRouteBuilder routes, Config config)
  476. {
  477. routes.MapSubdomainRoute(
  478. name: "RSS.Index",
  479. domains: new List<string>() { config.Host },
  480. subDomains: new List<string>() { "rss" },
  481. template: "",
  482. defaults: new { area = "RSS", controller = "RSS", action = "Index" }
  483. );
  484. routes.MapSubdomainRoute(
  485. name: "RSS.Blog",
  486. domains: new List<string>() { config.Host },
  487. subDomains: new List<string>() { "rss" },
  488. template: "Blog/{username?}",
  489. defaults: new { area = "RSS", controller = "RSS", action = "Blog" }
  490. );
  491. routes.MapSubdomainRoute(
  492. name: "RSS.Podcast",
  493. domains: new List<string>() { config.Host },
  494. subDomains: new List<string>() { "rss" },
  495. template: "Podcast",
  496. defaults: new { area = "RSS", controller = "RSS", action = "Podcast" }
  497. );
  498. }
  499. public static void BuildShortenerRoutes(this IRouteBuilder routes, Config config)
  500. {
  501. routes.MapSubdomainRoute(
  502. name: "Shortener.Index",
  503. domains: new List<string>() { config.Host },
  504. subDomains: new List<string>() { "shorten", "s" },
  505. template: "",
  506. defaults: new { area = "Shortener", controller = "Shortener", action = "Index" }
  507. );
  508. routes.MapSubdomainRoute(
  509. name: "Shortener.Delete",
  510. domains: new List<string>() { config.Host },
  511. subDomains: new List<string>() { "shorten", "s" },
  512. template: "Delete",
  513. defaults: new { area = "Shortener", controller = "Shortener", action = "Delete" }
  514. );
  515. routes.MapSubdomainRoute(
  516. name: "Shortener.Action",
  517. domains: new List<string>() { config.Host },
  518. subDomains: new List<string>() { "shorten", "s" },
  519. template: "Action/{action}",
  520. defaults: new { area = "Shortener", controller = "Shortener", action = "Index" }
  521. );
  522. routes.MapSubdomainRoute(
  523. name: "Shortener.View",
  524. domains: new List<string>() { config.ShortenerConfig.ShortenerHost, config.Host },
  525. subDomains: new List<string>() { string.Empty, "shortened" },
  526. template: "{url}",
  527. defaults: new { area = "Shortener", controller = "Shortener", action = "RedirectToUrl" }
  528. );
  529. routes.MapSubdomainRoute(
  530. name: "Shortener.Verify",
  531. domains: new List<string>() { config.ShortenerConfig.ShortenerHost },
  532. subDomains: new List<string>() { string.Empty },
  533. template: "",
  534. defaults: new { area = "Shortener", controller = "Shortener", action = "Verify" }
  535. );
  536. }
  537. public static void BuildStatsRoutes(this IRouteBuilder routes, Config config)
  538. {
  539. routes.MapSubdomainRoute(
  540. name: "Stats.Index",
  541. domains: new List<string>() { config.Host },
  542. subDomains: new List<string>() { "stats" },
  543. template: "",
  544. defaults: new { area = "Stats", controller = "Stats", action = "Index" }
  545. );
  546. routes.MapSubdomainRoute(
  547. name: "Stats.Action",
  548. domains: new List<string>() { config.Host },
  549. subDomains: new List<string>() { "stats" },
  550. template: "Action/{action}",
  551. defaults: new { area = "Stats", controller = "Stats", action = "Index" }
  552. );
  553. }
  554. public static void BuildTOSRoutes(this IRouteBuilder routes, Config config)
  555. {
  556. routes.MapSubdomainRoute(
  557. name: "TOS.Index",
  558. domains: new List<string>() { config.Host },
  559. subDomains: new List<string>() { "tos" },
  560. template: "",
  561. defaults: new { area = "TOS", controller = "TOS", action = "Index" }
  562. );
  563. }
  564. public static void BuildUploadRoutes(this IRouteBuilder routes, Config config)
  565. {
  566. routes.MapSubdomainRoute(
  567. name: "Upload.Index",
  568. domains: new List<string>() { config.Host },
  569. subDomains: new List<string>() { "upload", "u" },
  570. template: "",
  571. defaults: new { area = "Upload", controller = "Upload", action = "Index" }
  572. );
  573. routes.MapSubdomainRoute(
  574. name: "Upload.GenerateDeleteKey",
  575. domains: new List<string>() { config.Host },
  576. subDomains: new List<string>() { "upload", "u", "user" },
  577. template: "GenerateDeleteKey",
  578. defaults: new { area = "Upload", controller = "Upload", action = "GenerateDeleteKey" }
  579. );
  580. routes.MapSubdomainRoute(
  581. name: "Upload.Delete",
  582. domains: new List<string>() { config.Host },
  583. subDomains: new List<string>() { "upload", "u" },
  584. template: "Delete",
  585. defaults: new { area = "Upload", controller = "Upload", action = "Delete" }
  586. );
  587. routes.MapSubdomainRoute(
  588. name: "Upload.Download",
  589. domains: new List<string>() { config.Host },
  590. subDomains: new List<string>() { "upload", "u" },
  591. template: "{file}",
  592. defaults: new { area = "Upload", controller = "Upload", action = "Download" }
  593. );
  594. routes.MapSubdomainRoute(
  595. name: "Upload.DeleteByKey",
  596. domains: new List<string>() { config.Host },
  597. subDomains: new List<string>() { "upload", "u" },
  598. template: "{file}/{key}",
  599. defaults: new { area = "Upload", controller = "Upload", action = "DeleteByKey" }
  600. );
  601. routes.MapSubdomainRoute(
  602. name: "Upload.Action",
  603. domains: new List<string>() { config.Host },
  604. subDomains: new List<string>() { "upload", "u" },
  605. template: "Action/{action}",
  606. defaults: new { area = "Upload", controller = "Upload", action = "Index" }
  607. );
  608. }
  609. public static void BuildUserRoutes(this IRouteBuilder routes, Config config)
  610. {
  611. routes.MapSubdomainRoute(
  612. name: "User.Index",
  613. domains: new List<string>() { config.Host },
  614. subDomains: new List<string>() { "account" },
  615. template: "",
  616. defaults: new { area = "User", controller = "User", action = "Index" }
  617. );
  618. routes.MapSubdomainRoute(
  619. name: "User.GetPremium",
  620. domains: new List<string>() { config.Host },
  621. subDomains: new List<string>() { "account" },
  622. template: "GetPremium",
  623. defaults: new { area = "User", controller = "User", action = "GetPremium" }
  624. );
  625. routes.MapSubdomainRoute(
  626. name: "User.Register",
  627. domains: new List<string>() { config.Host },
  628. subDomains: new List<string>() { "account" },
  629. template: "Register",
  630. defaults: new { area = "User", controller = "User", action = "Register" }
  631. );
  632. routes.MapSubdomainRoute(
  633. name: "User.Login",
  634. domains: new List<string>() { config.Host },
  635. subDomains: new List<string>() { "account" },
  636. template: "Login",
  637. defaults: new { area = "User", controller = "User", action = "Login" }
  638. );
  639. routes.MapSubdomainRoute(
  640. name: "User.Logout",
  641. domains: new List<string>() { config.Host },
  642. subDomains: new List<string>() { "account" },
  643. template: "Logout",
  644. defaults: new { area = "User", controller = "User", action = "Logout" }
  645. );
  646. routes.MapSubdomainRoute(
  647. name: "User.Settings",
  648. domains: new List<string>() { config.Host },
  649. subDomains: new List<string>() { "account" },
  650. template: "Settings",
  651. defaults: new { area = "User", controller = "User", action = "Settings" }
  652. );
  653. routes.MapSubdomainRoute(
  654. name: "User.AccountSettings",
  655. domains: new List<string>() { config.Host },
  656. subDomains: new List<string>() { "account" },
  657. template: "Settings/Account",
  658. defaults: new { area = "User", controller = "User", action = "AccountSettings" }
  659. );
  660. routes.MapSubdomainRoute(
  661. name: "User.SecuritySettings",
  662. domains: new List<string>() { config.Host },
  663. subDomains: new List<string>() { "account" },
  664. template: "Settings/Security",
  665. defaults: new { area = "User", controller = "User", action = "SecuritySettings" }
  666. );
  667. routes.MapSubdomainRoute(
  668. name: "User.ProfileSettings",
  669. domains: new List<string>() { config.Host },
  670. subDomains: new List<string>() { "account" },
  671. template: "Settings/Profile",
  672. defaults: new { area = "User", controller = "User", action = "ProfileSettings" }
  673. );
  674. routes.MapSubdomainRoute(
  675. name: "User.DeveloperSettings",
  676. domains: new List<string>() { config.Host },
  677. subDomains: new List<string>() { "account" },
  678. template: "Settings/Developer",
  679. defaults: new { area = "User", controller = "User", action = "DeveloperSettings" }
  680. );
  681. routes.MapSubdomainRoute(
  682. name: "User.InviteSettings",
  683. domains: new List<string>() { config.Host },
  684. subDomains: new List<string>() { "account" },
  685. template: "Settings/Invites",
  686. defaults: new { area = "User", controller = "User", action = "InviteSettings" }
  687. );
  688. routes.MapSubdomainRoute(
  689. name: "User.BlogSettings",
  690. domains: new List<string>() { config.Host },
  691. subDomains: new List<string>() { "account" },
  692. template: "Settings/Blog",
  693. defaults: new { area = "User", controller = "User", action = "BlogSettings" }
  694. );
  695. routes.MapSubdomainRoute(
  696. name: "User.UploadSettings",
  697. domains: new List<string>() { config.Host },
  698. subDomains: new List<string>() { "account" },
  699. template: "Settings/Uploads",
  700. defaults: new { area = "User", controller = "User", action = "UploadSettings" }
  701. );
  702. routes.MapSubdomainRoute(
  703. name: "User.ResetPassword",
  704. domains: new List<string>() { config.Host },
  705. subDomains: new List<string>() { "account" },
  706. template: "ResetPassword/{username?}",
  707. defaults: new { area = "User", controller = "User", action = "ResetPassword" }
  708. );
  709. routes.MapSubdomainRoute(
  710. name: "User.VerifyResetPassword",
  711. domains: new List<string>() { config.Host },
  712. subDomains: new List<string>() { "account" },
  713. template: "SetPassword/{username}",
  714. defaults: new { area = "User", controller = "User", action = "VerifyResetPassword" }
  715. );
  716. routes.MapSubdomainRoute(
  717. name: "User.VerifyRecoveryEmail",
  718. domains: new List<string>() { config.Host },
  719. subDomains: new List<string>() { "account" },
  720. template: "VerifyEmail/{username}",
  721. defaults: new { area = "User", controller = "User", action = "VerifyRecoveryEmail" }
  722. );
  723. routes.MapSubdomainRoute(
  724. name: "User.ViewServiceData",
  725. domains: new List<string>() { config.Host },
  726. subDomains: new List<string>() { "account" },
  727. template: "ServiceData",
  728. defaults: new { area = "User", controller = "User", action = "ViewServiceData" }
  729. );
  730. routes.MapSubdomainRoute(
  731. name: "User.Action",
  732. domains: new List<string>() { config.Host },
  733. subDomains: new List<string>() { "account" },
  734. template: "Action/{action}",
  735. defaults: new { area = "User", controller = "User", action = "Index" }
  736. );
  737. routes.MapSubdomainRoute(
  738. name: "User.ViewProfile",
  739. domains: new List<string>() { config.Host },
  740. subDomains: new List<string>() { "user" },
  741. template: "{username?}",
  742. defaults: new { area = "User", controller = "User", action = "ViewProfile" }
  743. );
  744. routes.MapSubdomainRoute(
  745. name: "User.PGPKey",
  746. domains: new List<string>() { config.Host },
  747. subDomains: new List<string>() { "user" },
  748. template: "{username}/PGP",
  749. defaults: new { area = "User", controller = "User", action = "ViewRawPGP" }
  750. );
  751. }
  752. public static void BuildVaultRoutes(this IRouteBuilder routes, Config config)
  753. {
  754. routes.MapSubdomainRoute(
  755. name: "Vault.Index",
  756. domains: new List<string>() { config.Host },
  757. subDomains: new List<string>() { "vault", "v" },
  758. template: "",
  759. defaults: new { area = "Vault", controller = "Vault", action = "Index" }
  760. );
  761. routes.MapSubdomainRoute(
  762. name: "Vault.NewVault",
  763. domains: new List<string>() { config.Host },
  764. subDomains: new List<string>() { "vault", "v" },
  765. template: "Create",
  766. defaults: new { area = "Vault", controller = "Vault", action = "NewVault" }
  767. );
  768. routes.MapSubdomainRoute(
  769. name: "Vault.NewVaultFromService",
  770. domains: new List<string>() { config.Host },
  771. subDomains: new List<string>() { "vault", "v" },
  772. template: "Create/{type}",
  773. defaults: new { area = "Vault", controller = "Vault", action = "NewVaultFromService" }
  774. );
  775. routes.MapSubdomainRoute(
  776. name: "Vault.EditVault",
  777. domains: new List<string>() { config.Host },
  778. subDomains: new List<string>() { "vault", "v" },
  779. template: "Edit/{url}",
  780. defaults: new { area = "Vault", controller = "Vault", action = "EditVault" }
  781. );
  782. routes.MapSubdomainRoute(
  783. name: "Vault.Delete",
  784. domains: new List<string>() { config.Host },
  785. subDomains: new List<string>() { "vault", "v" },
  786. template: "Delete",
  787. defaults: new { area = "Vault", controller = "Vault", action = "Delete" }
  788. );
  789. routes.MapSubdomainRoute(
  790. name: "Vault.ViewVault",
  791. domains: new List<string>() { config.Host },
  792. subDomains: new List<string>() { "vault", "v" },
  793. template: "v/{id}",
  794. defaults: new { area = "Vault", controller = "Vault", action = "ViewVault" }
  795. );
  796. routes.MapSubdomainRoute(
  797. name: "Vault.Action",
  798. domains: new List<string>() { config.Host },
  799. subDomains: new List<string>() { "vault", "v" },
  800. template: "Action/{action}",
  801. defaults: new { area = "Vault", controller = "Vault", action = "Index" }
  802. );
  803. }
  804. }
  805. }