91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用SpringBoot怎么實現私有云網盤

發布時間:2021-05-31 17:31:15 來源:億速云 閱讀:161 作者:Leah 欄目:編程語言

這期內容當中小編將會給大家帶來有關使用SpringBoot怎么實現私有云網盤,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

項目配置

項目在第三方插件進行二次開發,基于 SpringBoot 注解配置實現。

application.properties 配置:

# 執行類,內部調用,實現前端相關功能
file-manager.command=com.itstyle.cloud.common.elfinder.command
file-manager.thumbnail.width=80
file-manager.volumes[0].Node=
file-manager.volumes[0].source=fileSystem
file-manager.volumes[0].alias=file
# 文件存放目錄,可以自定義
file-manager.volumes[0].path=D:/cloudFile
file-manager.volumes[0]._default=true
file-manager.volumes[0].locale=
file-manager.volumes[0].constraint.locked=false
file-manager.volumes[0].constraint.readable=true
file-manager.volumes[0].constraint.writable=true

ElfinderConfiguration 讀取配置:

@Component
@ConfigurationProperties(prefix="file-manager") //接收application.properties中的file-manager下面的屬性
public class ElfinderConfiguration {

  private Thumbnail thumbnail;

  private String command;

  private List<Node> volumes;

  private Long maxUploadSize = -1L;

  //省略部分代碼
}

elfinderStorageFactory 初始化 基礎Bean:

@Configuration
public class ElFinderConfig {

  @Autowired
  private ElfinderConfiguration elfinderConfiguration;

  @Bean(name = "commandFactory")
  public CommandFactory getCommandFactory() {
    CommandFactory commandFactory = new CommandFactory();
    commandFactory.setClassNamePattern(elfinderConfiguration.getCommand()+".%sCommand");
    return commandFactory;
  }

  @Bean(name = "elfinderStorageFactory")
  public ElfinderStorageFactory getElfinderStorageFactory() {
    DefaultElfinderStorageFactory elfinderStorageFactory = new DefaultElfinderStorageFactory();
    elfinderStorageFactory.setElfinderStorage(getElfinderStorage());
    return elfinderStorageFactory;
  }

  @Bean(name = "elfinderStorage")
  public ElfinderStorage getElfinderStorage() {
    DefaultElfinderStorage defaultElfinderStorage = new DefaultElfinderStorage();

    // creates thumbnail
    DefaultThumbnailWidth defaultThumbnailWidth = new DefaultThumbnailWidth();
    defaultThumbnailWidth.setThumbnailWidth(elfinderConfiguration.getThumbnail().getWidth().intValue());

    // creates volumes, volumeIds, volumeLocale and volumeSecurities
    Character defaultVolumeId = 'A';
    List<Node> elfinderConfigurationVolumes = elfinderConfiguration.getVolumes();
    List<Volume> elfinderVolumes = new ArrayList<>(elfinderConfigurationVolumes.size());
    Map<Volume, String> elfinderVolumeIds = new HashMap<>(elfinderConfigurationVolumes.size());
    Map<Volume, Locale> elfinderVolumeLocales = new HashMap<>(elfinderConfigurationVolumes.size());
    List<VolumeSecurity> elfinderVolumeSecurities = new ArrayList<>();

    // creates volumes
    for (Node elfinderConfigurationVolume : elfinderConfigurationVolumes) {

      final String alias = elfinderConfigurationVolume.getAlias();
      final String path = elfinderConfigurationVolume.getPath();
      final String source = elfinderConfigurationVolume.getSource();
      final String locale = elfinderConfigurationVolume.getLocale();
      final boolean isLocked = elfinderConfigurationVolume.getConstraint().isLocked();
      final boolean isReadable = elfinderConfigurationVolume.getConstraint().isReadable();
      final boolean isWritable = elfinderConfigurationVolume.getConstraint().isWritable();

      // creates new volume
      Volume volume = VolumeSources.of(source).newInstance(alias, path);

      elfinderVolumes.add(volume);
      elfinderVolumeIds.put(volume, Character.toString(defaultVolumeId));
      elfinderVolumeLocales.put(volume, LocaleUtils.toLocale(locale));

      // creates security constraint
      SecurityConstraint securityConstraint = new SecurityConstraint();
      securityConstraint.setLocked(isLocked);
      securityConstraint.setReadable(isReadable);
      securityConstraint.setWritable(isWritable);

      // creates volume pattern and volume security
      final String volumePattern = Character.toString(defaultVolumeId) + ElFinderConstants.ELFINDER_VOLUME_SERCURITY_REGEX;
      elfinderVolumeSecurities.add(new DefaultVolumeSecurity(volumePattern, securityConstraint));

      // prepare next volumeId character
      defaultVolumeId++;
    }

    defaultElfinderStorage.setThumbnailWidth(defaultThumbnailWidth);
    defaultElfinderStorage.setVolumes(elfinderVolumes);
    defaultElfinderStorage.setVolumeIds(elfinderVolumeIds);
    defaultElfinderStorage.setVolumeLocales(elfinderVolumeLocales);
    defaultElfinderStorage.setVolumeSecurities(elfinderVolumeSecurities);
    return defaultElfinderStorage;
  }
}

CloudDiskController 控制層實現:

@Controller
@RequestMapping("elfinder/connector")
public class CloudDiskController {

  private static final Logger logger = LoggerFactory.getLogger(CloudDiskController.class);

  public static final String OPEN_STREAM = "openStream";
  public static final String GET_PARAMETER = "getParameter";

  @Resource(name = "commandFactory")
  private ElfinderCommandFactory elfinderCommandFactory;

  @Resource(name = "elfinderStorageFactory")
  private ElfinderStorageFactory elfinderStorageFactory;

  @RequestMapping
  public void connector(HttpServletRequest request, final HttpServletResponse response) throws IOException {
    try {
      response.setCharacterEncoding("UTF-8");
      request = processMultipartContent(request);
    } catch (Exception e) {
      throw new IOException(e.getMessage());
    }


    String cmd = request.getParameter(ElFinderConstants.ELFINDER_PARAMETER_COMMAND);
    ElfinderCommand elfinderCommand = elfinderCommandFactory.get(cmd);

    try {
      final HttpServletRequest protectedRequest = request;
      elfinderCommand.execute(new ElfinderContext() {
        @Override
        public ElfinderStorageFactory getVolumeSourceFactory() {
          return elfinderStorageFactory;
        }

        @Override
        public HttpServletRequest getRequest() {
          return protectedRequest;
        }

        @Override
        public HttpServletResponse getResponse() {
          return response;
        }
      });
    } catch (Exception e) {
      logger.error("Unknown error", e);
    }
  }
  //省略部分代碼
}

最后,前端頁面引入:

<div id="elfinder"></div>
<script type="text/javascript" charset="utf-8">
    window.onload = function() {
      elFinder.prototype.loadCss('/elfinder/jquery-ui-1.12.1.custom/jquery-ui.css');
      $('#elfinder').elfinder({
        url : '/elfinder/connector',
        lang: 'zh_CN',
        height : window.innerHeight-20,
        commandsOptions: {
          edit: {
            editors : [
              {
                info:{
                  name:'編輯',
                  urlAsContent: false
                },
                // ACE Editor
                // `mimes` is not set for support everything kind of text file
                load : function(textarea) {
                  var self = this,
                    dfrd = $.Deferred(),
                    cdn = './elfinder/ace/',
                    init = function() {
                      if (typeof ace === 'undefined') {
                        console.log(cdn);
                        this.fm.loadScript([
                          cdn+'/ace.js',
                          cdn+'/ext-modelist.js',
                          cdn+'/ext-settings_menu.js',
                          cdn+'/ext-language_tools.js'
                        ], start);
                      } else {
                        start();
                      }
                    },
                    start = function() {
                      var editor, editorBase, mode,
                        ta = $(textarea),
                        taBase = ta.parent(),
                        dialog = taBase.parent(),
                        id = textarea.id + '_ace',
                        ext = self.file.name.replace(/^.+\.([^.]+)|(.+)$/, '$1$2').toLowerCase(),
                        // MIME/mode map
                        mimeMode = {
                          'text/x-php'       : 'php',
                          'application/x-php'    : 'php',
                          'text/html'        : 'html',
                          'application/xhtml+xml'  : 'html',
                          'text/javascript'     : 'javascript',
                          'application/javascript' : 'javascript',
                          'text/css'        : 'css',
                          'text/x-c'        : 'c_cpp',
                          'text/x-csrc'       : 'c_cpp',
                          'text/x-chdr'       : 'c_cpp',
                          'text/x-c++'       : 'c_cpp',
                          'text/x-c++src'      : 'c_cpp',
                          'text/x-c++hdr'      : 'c_cpp',
                          'text/x-shellscript'   : 'sh',
                          'application/x-csh'    : 'sh',
                          'text/x-python'      : 'python',
                          'text/x-java'       : 'java',
                          'text/x-java-source'   : 'java',
                          'text/x-ruby'       : 'ruby',
                          'text/x-perl'       : 'perl',
                          'application/x-perl'   : 'perl',
                          'text/x-sql'       : 'sql',
                          'text/xml'        : 'xml',
                          'application/docbook+xml' : 'xml',
                          'application/xml'     : 'xml'
                        };

                      // set basePath of ace
                      ace.config.set('basePath', cdn);

                      // set base height
                      taBase.height(taBase.height());

                      // detect mode
                      mode = ace.require('ace/ext/modelist').getModeForPath('/' + self.file.name).name;
                      if (mode === 'text') {
                        if (mimeMode[self.file.mime]) {
                          mode = mimeMode[self.file.mime];
                        }
                      }

                      // show MIME:mode in title bar
                      taBase.prev().children('.elfinder-dialog-title').append(' (' + self.file.mime + ' : ' + mode.split(/[\/\\]/).pop() + ')');
                      // TextArea button and Setting button
                      $('<div class="ui-dialog-buttonset"/>').css('float', 'left')
                        .append(
                          $('<button>文本框</button>')
                            .button()
                            .on('click', function(){
                              if (ta.data('ace')) {
                                ta.removeData('ace');
                                editorBase.hide();
                                ta.val(editor.session.getValue()).show().focus();
                                $(this).text('編輯器');
                              } else {
                                ta.data('ace', true);
                                editorBase.show();
                                editor.setValue(ta.hide().val(), -1);
                                editor.focus();
                                $(this).text('文本框');
                              }
                            })
                        )
                        .append(
                          $('<button>Ace editor setting</button>')
                            .button({
                              icons: {
                                primary: 'ui-icon-gear',
                                secondary: 'ui-icon-triangle-1-e'
                              },
                              text: false
                            })
                            .on('click', function(){
                              editor.showSettingsMenu();
                            })
                        )
                        .prependTo(taBase.next());

                      // Base node of Ace editor
                      editorBase = $('<div id="'+id+'" />').text(ta.val()).insertBefore(ta.hide());

                      // Ace editor configure
                      ta.data('ace', true);
                      editor = ace.edit(id);
                      ace.require('ace/ext/language_tools');
                      ace.require('ace/ext/settings_menu').init(editor);
                      editor.$blockScrolling = Infinity;
                      editor.setOptions({
                        theme: 'ace/theme/dawn',
                        mode: 'ace/mode/' + mode,
                        fontSize: '14px',
                        wrap: true,
                        enableBasicAutocompletion: true,
                        enableSnippets: true,
                        enableLiveAutocompletion: true
                      });
                      editor.commands.addCommand({
                        name : "saveFile",
                        bindKey: {
                          win : 'Ctrl-s',
                          mac : 'Command-s'
                        },
                        exec: function(editor) {
                          self.doSave();
                        }
                      });
                      editor.commands.addCommand({
                        name : "closeEditor",
                        bindKey: {
                          win : 'Ctrl-w|Ctrl-q',
                          mac : 'Command-w|Command-q'
                        },
                        exec: function(editor) {
                          self.doCancel();
                        }
                      });

                      editor.resize();

                      dfrd.resolve(editor);
                    };

                  // init & start
                  init();

                  return dfrd;
                },
                close : function(textarea, instance) {
                  if (instance) {
                    instance.destroy();
                    $(textarea).show();
                  }
                },
                save : function(textarea, instance) {
                  instance && $(textarea).data('ace') && (textarea.value = instance.session.getValue());
                },
                focus : function(textarea, instance) {
                  instance && $(textarea).data('ace') && instance.focus();
                },
                resize : function(textarea, instance, e, data) {
                  instance && instance.resize();
                }
              }
            ]
          },
          quicklook : {
            // to enable preview with Google Docs Viewer
            googleDocsMimes : ['application/pdf', 'image/tiff', 'application/vnd.ms-office', 'application/msword', 'application/vnd.ms-word', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
          }
        }
      });
    };
  </script>

上述就是小編為大家分享的使用SpringBoot怎么實現私有云網盤了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

麟游县| 玉树县| 沐川县| 乌拉特前旗| 公主岭市| 集安市| 关岭| 孟津县| 新疆| 香河县| 鲁山县| 剑川县| 万荣县| 松溪县| 茂名市| 隆安县| 建水县| 红河县| 荔波县| 河源市| 湘阴县| 宜春市| 双城市| 克拉玛依市| 共和县| 丁青县| 民权县| 沁水县| 阿克陶县| 郴州市| 乌拉特中旗| 扎赉特旗| 蒙自县| 大丰市| 旬阳县| 永吉县| 道孚县| 太和县| 古蔺县| 精河县| 曲周县|