|
| 1 | +// Copyright (c) Jupyter Development Team. |
| 2 | +// Distributed under the terms of the Modified BSD License. |
| 3 | + |
| 4 | +import { Signal, ISignal } from '@lumino/signaling'; |
| 5 | + |
| 6 | +import { DocumentRegistry } from '@jupyterlab/docregistry'; |
| 7 | + |
| 8 | +import { Contents, ServerConnection } from '@jupyterlab/services'; |
| 9 | + |
| 10 | +/** |
| 11 | + * A Contents.IDrive implementation that serves as a read-only |
| 12 | + * view onto the drive repositories. |
| 13 | + */ |
| 14 | +export class Drive implements Contents.IDrive { |
| 15 | + /** |
| 16 | + * Construct a new drive object. |
| 17 | + * |
| 18 | + * @param options - The options used to initialize the object. |
| 19 | + */ |
| 20 | + constructor(registry: DocumentRegistry) { |
| 21 | + this._serverSettings = ServerConnection.makeSettings(); |
| 22 | + } |
| 23 | + /** |
| 24 | + * The Drive base URL |
| 25 | + */ |
| 26 | + get baseUrl(): string { |
| 27 | + return this._baseUrl; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * The Drive base URL is set by the settingsRegistry change hook |
| 32 | + */ |
| 33 | + set baseUrl(url: string) { |
| 34 | + this._baseUrl = url; |
| 35 | + } |
| 36 | + /** |
| 37 | + * The Drive name getter |
| 38 | + */ |
| 39 | + get name(): string { |
| 40 | + return this._name; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * The Drive name setter */ |
| 45 | + set name(name: string) { |
| 46 | + this._name = name; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * The Drive provider getter |
| 51 | + */ |
| 52 | + get provider(): string { |
| 53 | + return this._provider; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * The Drive provider setter */ |
| 58 | + set provider(name: string) { |
| 59 | + this._provider = name; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * The Drive is Active getter |
| 64 | + */ |
| 65 | + get isActive(): boolean { |
| 66 | + return this._isActive; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * The Drive isActive provider setter */ |
| 71 | + set isActive(isActive: boolean) { |
| 72 | + this._isActive = isActive; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Settings for the notebook server. |
| 77 | + */ |
| 78 | + get serverSettings(): ServerConnection.ISettings { |
| 79 | + return this._serverSettings; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * A signal emitted when a file operation takes place. |
| 84 | + */ |
| 85 | + get fileChanged(): ISignal<this, Contents.IChangedArgs> { |
| 86 | + return this._fileChanged; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Test whether the manager has been disposed. |
| 91 | + */ |
| 92 | + get isDisposed(): boolean { |
| 93 | + return this._isDisposed; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Dispose of the resources held by the manager. |
| 98 | + */ |
| 99 | + dispose(): void { |
| 100 | + if (this.isDisposed) { |
| 101 | + return; |
| 102 | + } |
| 103 | + this._isDisposed = true; |
| 104 | + Signal.clearData(this); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Get an encoded download url given a file path. |
| 109 | + * |
| 110 | + * @param path - An absolute POSIX file path on the server. |
| 111 | + * |
| 112 | + * #### Notes |
| 113 | + * It is expected that the path contains no relative paths, |
| 114 | + * use [[ContentsManager.getAbsolutePath]] to get an absolute |
| 115 | + * path if necessary. |
| 116 | + */ |
| 117 | + getDownloadUrl(path: string): Promise<string> { |
| 118 | + // Parse the path into user/repo/path |
| 119 | + console.log('Path is:', path); |
| 120 | + return Promise.reject('Empty getDownloadUrl method'); |
| 121 | + } |
| 122 | + |
| 123 | + get( |
| 124 | + path: string, |
| 125 | + options?: Contents.IFetchOptions |
| 126 | + ): Promise<Contents.IModel> { |
| 127 | + return Promise.reject('Empty get method'); |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Create a new untitled file or directory in the specified directory path. |
| 132 | + * |
| 133 | + * @param options: The options used to create the file. |
| 134 | + * |
| 135 | + * @returns A promise which resolves with the created file content when the |
| 136 | + * file is created. |
| 137 | + */ |
| 138 | + newUntitled(options: Contents.ICreateOptions = {}): Promise<Contents.IModel> { |
| 139 | + return Promise.reject('Repository is read only'); |
| 140 | + } |
| 141 | + |
| 142 | + /** |
| 143 | + * Delete a file. |
| 144 | + * |
| 145 | + * @param path - The path to the file. |
| 146 | + * |
| 147 | + * @returns A promise which resolves when the file is deleted. |
| 148 | + */ |
| 149 | + delete(path: string): Promise<void> { |
| 150 | + return Promise.reject('Repository is read only'); |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Rename a file or directory. |
| 155 | + * |
| 156 | + * @param path - The original file path. |
| 157 | + * |
| 158 | + * @param newPath - The new file path. |
| 159 | + * |
| 160 | + * @returns A promise which resolves with the new file contents model when |
| 161 | + * the file is renamed. |
| 162 | + */ |
| 163 | + rename(path: string, newPath: string): Promise<Contents.IModel> { |
| 164 | + return Promise.reject('Repository is read only'); |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * Save a file. |
| 169 | + * |
| 170 | + * @param path - The desired file path. |
| 171 | + * |
| 172 | + * @param options - Optional overrides to the model. |
| 173 | + * |
| 174 | + * @returns A promise which resolves with the file content model when the |
| 175 | + * file is saved. |
| 176 | + */ |
| 177 | + save( |
| 178 | + path: string, |
| 179 | + options: Partial<Contents.IModel> |
| 180 | + ): Promise<Contents.IModel> { |
| 181 | + return Promise.reject('Repository is read only'); |
| 182 | + } |
| 183 | + |
| 184 | + /** |
| 185 | + * Copy a file into a given directory. |
| 186 | + * |
| 187 | + * @param path - The original file path. |
| 188 | + * |
| 189 | + * @param toDir - The destination directory path. |
| 190 | + * |
| 191 | + * @returns A promise which resolves with the new contents model when the |
| 192 | + * file is copied. |
| 193 | + */ |
| 194 | + copy(fromFile: string, toDir: string): Promise<Contents.IModel> { |
| 195 | + return Promise.reject('Repository is read only'); |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * Create a checkpoint for a file. |
| 200 | + * |
| 201 | + * @param path - The path of the file. |
| 202 | + * |
| 203 | + * @returns A promise which resolves with the new checkpoint model when the |
| 204 | + * checkpoint is created. |
| 205 | + */ |
| 206 | + createCheckpoint(path: string): Promise<Contents.ICheckpointModel> { |
| 207 | + return Promise.reject('Repository is read only'); |
| 208 | + } |
| 209 | + |
| 210 | + /** |
| 211 | + * List available checkpoints for a file. |
| 212 | + * |
| 213 | + * @param path - The path of the file. |
| 214 | + * |
| 215 | + * @returns A promise which resolves with a list of checkpoint models for |
| 216 | + * the file. |
| 217 | + */ |
| 218 | + listCheckpoints(path: string): Promise<Contents.ICheckpointModel[]> { |
| 219 | + return Promise.resolve([]); |
| 220 | + } |
| 221 | + |
| 222 | + /** |
| 223 | + * Restore a file to a known checkpoint state. |
| 224 | + * |
| 225 | + * @param path - The path of the file. |
| 226 | + * |
| 227 | + * @param checkpointID - The id of the checkpoint to restore. |
| 228 | + * |
| 229 | + * @returns A promise which resolves when the checkpoint is restored. |
| 230 | + */ |
| 231 | + restoreCheckpoint(path: string, checkpointID: string): Promise<void> { |
| 232 | + return Promise.reject('Repository is read only'); |
| 233 | + } |
| 234 | + |
| 235 | + /** |
| 236 | + * Delete a checkpoint for a file. |
| 237 | + * |
| 238 | + * @param path - The path of the file. |
| 239 | + * |
| 240 | + * @param checkpointID - The id of the checkpoint to delete. |
| 241 | + * |
| 242 | + * @returns A promise which resolves when the checkpoint is deleted. |
| 243 | + */ |
| 244 | + deleteCheckpoint(path: string, checkpointID: string): Promise<void> { |
| 245 | + return Promise.reject('Read only'); |
| 246 | + } |
| 247 | + |
| 248 | + private _serverSettings: ServerConnection.ISettings; |
| 249 | + private _name: string = ''; |
| 250 | + private _provider: string = ''; |
| 251 | + private _baseUrl: string = ''; |
| 252 | + private _isActive: boolean = false; |
| 253 | + private _fileChanged = new Signal<this, Contents.IChangedArgs>(this); |
| 254 | + private _isDisposed: boolean = false; |
| 255 | +} |
0 commit comments