You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /**
  2. * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  3. *
  4. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  5. * @author John Molakvoæ <skjnldsv@protonmail.com>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. import { subscribe } from '@nextcloud/event-bus'
  25. import { addScript, addStyle } from './legacy-loader'
  26. import {
  27. ajaxConnectionLostHandler,
  28. processAjaxError,
  29. registerXHRForErrorProcessing,
  30. } from './xhr-error'
  31. import Apps from './apps'
  32. import { AppConfig, appConfig } from './appconfig'
  33. import { appSettings } from './appsettings'
  34. import appswebroots from './appswebroots'
  35. import Backbone from './backbone'
  36. import {
  37. basename,
  38. dirname,
  39. encodePath,
  40. isSamePath,
  41. joinPaths,
  42. } from '@nextcloud/paths'
  43. import {
  44. build as buildQueryString,
  45. parse as parseQueryString,
  46. } from './query-string'
  47. import Config from './config'
  48. import {
  49. coreApps,
  50. menuSpeed,
  51. PERMISSION_ALL,
  52. PERMISSION_CREATE,
  53. PERMISSION_DELETE,
  54. PERMISSION_NONE,
  55. PERMISSION_READ,
  56. PERMISSION_SHARE,
  57. PERMISSION_UPDATE,
  58. TAG_FAVORITE,
  59. } from './constants'
  60. import ContactsMenu from './contactsmenu'
  61. import { currentUser, getCurrentUser } from './currentuser'
  62. import Dialogs from './dialogs'
  63. import EventSource from './eventsource'
  64. import { get, set } from './get_set'
  65. import { getCapabilities } from './capabilities'
  66. import {
  67. getHost,
  68. getHostName,
  69. getPort,
  70. getProtocol,
  71. } from './host'
  72. import {
  73. getToken as getRequestToken,
  74. } from './requesttoken'
  75. import {
  76. hideMenus,
  77. registerMenu,
  78. showMenu,
  79. unregisterMenu,
  80. } from './menu'
  81. import { isUserAdmin } from './admin'
  82. import L10N, {
  83. getLanguage,
  84. getLocale,
  85. } from './l10n'
  86. import {
  87. getCanonicalLocale,
  88. } from '@nextcloud/l10n'
  89. import {
  90. generateUrl,
  91. generateFilePath,
  92. generateOcsUrl,
  93. generateRemoteUrl,
  94. getRootUrl,
  95. imagePath,
  96. linkTo,
  97. } from '@nextcloud/router'
  98. import {
  99. linkToRemoteBase,
  100. } from './routing'
  101. import msg from './msg'
  102. import Notification from './notification'
  103. import PasswordConfirmation from './password-confirmation'
  104. import Plugins from './plugins'
  105. import { theme } from './theme'
  106. import Util from './util'
  107. import { debug } from './debug'
  108. import { redirect, reload } from './navigation'
  109. import webroot from './webroot'
  110. /** @namespace OC */
  111. export default {
  112. /*
  113. * Constants
  114. */
  115. coreApps,
  116. menuSpeed,
  117. PERMISSION_ALL,
  118. PERMISSION_CREATE,
  119. PERMISSION_DELETE,
  120. PERMISSION_NONE,
  121. PERMISSION_READ,
  122. PERMISSION_SHARE,
  123. PERMISSION_UPDATE,
  124. TAG_FAVORITE,
  125. /*
  126. * Deprecated helpers to be removed
  127. */
  128. /**
  129. * Check if a user file is allowed to be handled.
  130. *
  131. * @param {string} file to check
  132. * @return {boolean}
  133. * @deprecated 17.0.0
  134. */
  135. fileIsBlacklisted: file => !!(file.match(Config.blacklist_files_regex)),
  136. addScript,
  137. addStyle,
  138. Apps,
  139. AppConfig,
  140. appConfig,
  141. appSettings,
  142. appswebroots,
  143. Backbone,
  144. ContactsMenu,
  145. config: Config,
  146. /**
  147. * Currently logged in user or null if none
  148. *
  149. * @type {string}
  150. * @deprecated use `getCurrentUser` from https://www.npmjs.com/package/@nextcloud/auth
  151. */
  152. currentUser,
  153. dialogs: Dialogs,
  154. EventSource,
  155. /**
  156. * Returns the currently logged in user or null if there is no logged in
  157. * user (public page mode)
  158. *
  159. * @since 9.0.0
  160. * @deprecated 19.0.0 use `getCurrentUser` from https://www.npmjs.com/package/@nextcloud/auth
  161. */
  162. getCurrentUser,
  163. isUserAdmin,
  164. L10N,
  165. /**
  166. * Ajax error handlers
  167. *
  168. * @todo remove from here and keep internally -> requires new tests
  169. */
  170. _ajaxConnectionLostHandler: ajaxConnectionLostHandler,
  171. _processAjaxError: processAjaxError,
  172. registerXHRForErrorProcessing,
  173. /**
  174. * Capabilities
  175. *
  176. * @type {Array}
  177. * @deprecated 20.0.0 use @nextcloud/capabilities instead
  178. */
  179. getCapabilities,
  180. /*
  181. * Legacy menu helpers
  182. */
  183. hideMenus,
  184. registerMenu,
  185. showMenu,
  186. unregisterMenu,
  187. /*
  188. * Path helpers
  189. */
  190. /**
  191. * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths
  192. */
  193. basename,
  194. /**
  195. * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths
  196. */
  197. encodePath,
  198. /**
  199. * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths
  200. */
  201. dirname,
  202. /**
  203. * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths
  204. */
  205. isSamePath,
  206. /**
  207. * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths
  208. */
  209. joinPaths,
  210. /**
  211. * Host (url) helpers
  212. */
  213. getHost,
  214. getHostName,
  215. getPort,
  216. getProtocol,
  217. /**
  218. * @deprecated 20.0.0 use `getCanonicalLocale` from https://www.npmjs.com/package/@nextcloud/l10n
  219. */
  220. getCanonicalLocale,
  221. getLocale,
  222. getLanguage,
  223. /**
  224. * Loads translations for the given app asynchronously.
  225. *
  226. * @param {string} app app name
  227. * @param {Function} callback callback to call after loading
  228. * @return {Promise}
  229. * @deprecated 17.0.0 use OC.L10N.load instead
  230. */
  231. addTranslations: L10N.load,
  232. /**
  233. * Query string helpers
  234. */
  235. buildQueryString,
  236. parseQueryString,
  237. msg,
  238. Notification,
  239. PasswordConfirmation,
  240. Plugins,
  241. theme,
  242. Util,
  243. debug,
  244. /**
  245. * @deprecated 19.0.0 use `generateFilePath` from https://www.npmjs.com/package/@nextcloud/router
  246. */
  247. filePath: generateFilePath,
  248. /**
  249. * @deprecated 19.0.0 use `generateUrl` from https://www.npmjs.com/package/@nextcloud/router
  250. */
  251. generateUrl,
  252. /**
  253. * @deprecated 19.0.0 use https://lodash.com/docs#get
  254. */
  255. get: get(window),
  256. /**
  257. * @deprecated 19.0.0 use https://lodash.com/docs#set
  258. */
  259. set: set(window),
  260. /**
  261. * @deprecated 19.0.0 use `getRootUrl` from https://www.npmjs.com/package/@nextcloud/router
  262. */
  263. getRootPath: getRootUrl,
  264. /**
  265. * @deprecated 19.0.0 use `imagePath` from https://www.npmjs.com/package/@nextcloud/router
  266. */
  267. imagePath,
  268. redirect,
  269. reload,
  270. requestToken: getRequestToken(),
  271. /**
  272. * @deprecated 19.0.0 use `linkTo` from https://www.npmjs.com/package/@nextcloud/router
  273. */
  274. linkTo,
  275. /**
  276. * @param {string} service service name
  277. * @param {number} version OCS API version
  278. * @return {string} OCS API base path
  279. * @deprecated 19.0.0 use `generateOcsUrl` from https://www.npmjs.com/package/@nextcloud/router
  280. */
  281. linkToOCS: (service, version) => {
  282. return generateOcsUrl(service, {}, {
  283. ocsVersion: version || 1,
  284. }) + '/'
  285. },
  286. /**
  287. * @deprecated 19.0.0 use `generateRemoteUrl` from https://www.npmjs.com/package/@nextcloud/router
  288. */
  289. linkToRemote: generateRemoteUrl,
  290. linkToRemoteBase,
  291. /**
  292. * Relative path to Nextcloud root.
  293. * For example: "/nextcloud"
  294. *
  295. * @type {string}
  296. *
  297. * @deprecated 19.0.0 use `getRootUrl` from https://www.npmjs.com/package/@nextcloud/router
  298. * @see OC#getRootPath
  299. */
  300. webroot,
  301. }
  302. // Keep the request token prop in sync
  303. subscribe('csrf-token-update', e => {
  304. OC.requestToken = e.token
  305. // Logging might help debug (Sentry) issues
  306. console.info('OC.requestToken changed', e.token)
  307. })